Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does gRPC resend messages

Tags:

grpc

grpc-java

A question related to the idempotence of serverside code, or the necessity of it. Either for gRPC in general, or specifically to the java implementation.

Is it possible that when we send a message once from a client, that it is handled twice by our service implementation? Maybe this would be related to retries when service seems unavailable; or could be configured by some policy?

like image 834
O.O. Avatar asked Jan 28 '26 20:01

O.O.


2 Answers

Right now, when you send a message from a client it will be seen (at most) once by the server. If you have idempotent methods, you will soon be able to specify a policy for automatic retries (design doc) but these retry attempts will not be enabled by default. You do not have to worry about the gRPC library sending your RPCs more than once unless you have this configured in your retry policy.

like image 51
Eric G Avatar answered Jan 30 '26 23:01

Eric G


According to grpc-java/5724, the retry logic has already been implemented. The OP does it using a Map, that is not type safe. A better way would be as follows:

NettyChannelBuilder builder = NettyChannelBuilder.forAddress(host, port)
  .enableRetry()        
  .maxRetryAttempts(3);

There are other retry configurations available on the NettyChannelBuilder.

There's also an example here, although it's pretty hard to find.

like image 34
Abhijit Sarkar Avatar answered Jan 30 '26 23:01

Abhijit Sarkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!