{ interceptCall: function(callConstructor, options) {
var call = callConstructor(options);
return (new InterceptingCallBuilder(call)).withInterceptBatch(function(batch, next, responder) { var cachedResponse = _getCachedResponse(batch); if (cachedResponse) { var response = (new ResponseBuilder).withMessage(cachedResponse).withStatus(grpc.status.OK).build(); responder(null, response); } else { next(batch); } }).build(); }}
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/878bc96d-f6a7-4504-b106-6654b70de7d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The proposal says "The interceptCall method allows developers to modify the call options". What are the semantics of modifying these options, particularly the ones that apply to an entire client, not a single method (channelCredentials and host)? Is the MethodDescriptor object supposed to be modifiable?
The semantics of modifying the call options are whatever the semantics of modifying the options parameter to `getCall` in client.js are ( https://github.com/grpc/grpc/blob/master/src/node/src/client.js#L332 )
I could limit the options exposed to the options exposed in grpc-java's CallOptions class if that's preferrable:
deadline
authority (host)
credentials
customOptions
The MethodDescriptor should not be modified. I've added a note for that.
The three advanced examples use "StatusBuilder", but it doesn't seem to be defined anywhere.
They also only appear to work for unary calls. This should at least be mentioned.
An example of a caching interceptor for unary RPCs which stores the provided listener for later use (short-circuiting
the call if there is a cache hit):
An example retry interceptor for unary RPCs creates new calls when the status shows a failure:
An example of providing fallbacks to failed requests for unary or client-streaming RPCs:
In the Retry example, the call is retried for any non-OK status code. There are some nuances that should be considered there, like idempotency and the potential to increase traffic to overwhelmed servers that are timing out. We already have a more complete proposal for handling retries in the core at https://github.com/grpc/proposal/blob/master/A6.md, so I think it may not be the best idea to encourage people to retry calls with a relatively simple implementation at a higher level.
Also, the Caching example appears to use "savedMessage" and "storedMessage" interchangeably, and it does the same with "savedListener" and "storedListener". And the proposal should say "Implemented in: Javascript" at the top, instead of "Java, Go".
Fixed.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/0b852ae7-d5da-4302-9596-3d71884bc631%40googlegroups.com.
const interceptor = function(options) {
return new InterceptingCall(options, {
sendMessage: function(message, next) {
next(_doSomething(message));
}
});
};
client.myCall(message, { interceptors: [interceptor] });
const interceptor = {
interceptCall: function(options) {
return new InterceptingCall(options, {
sendMessage: function(message, next) {
next(_doSomething(message));
}
});
}
};
client.myCall(message, { interceptors: [interceptor] });
That's the same API as proposed, except with the interceptCall function promoted to represent the interceptor. Maybe the examples are confusing because they use the builders? This is the same example but using the API in the proposal:
const interceptor = {
interceptCall: function(options) {
return new InterceptingCall(options, {
sendMessage: function(message, next) {
next(_doSomething(message));
}
});
}
};
client.myCall(message, { interceptors: [interceptor] });
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/504cc473-66c5-4f1b-92f1-34f3414ccf15%40googlegroups.com.