SOFARPC supports a framework-level retry policy when using the FailOver cluster mode, which is the default. A retry is triggered only by a server-side framework exception or a timeout exception. SOFARPC does not retry calls that fail because of business logic exceptions. By default, the number of retries is zero.
When retrying on timeout exceptions, the server-side service must be idempotent to prevent potential risks.
XML configuration
If you subscribe to a service using XML, you can set the retries parameter of sofa:global-attrs to specify the number of retries:
<sofa:reference jvm-first="false" id="retriesServiceReferenceBolt" interface="com.alipay.sofa.rpc.samples.retries.RetriesService">
<sofa:binding.bolt>
<sofa:global-attrs retries="2"/>
</sofa:binding.bolt>
</sofa:reference>Annotation method
If you use annotations, you can set the retries property of the @SofaReferenceBinding annotation to specify the number of retries:
@SofaReference(binding =@SofaReferenceBinding(bindingType ="bolt", retries =2))
private SampleService sampleService;API in a Spring environment
In a Spring environment, you can call the setRetries method of BoltBindingParam to set the number of retries:
BoltBindingParam boltBindingParam =new BoltBindingParam();
boltBindingParam.setRetries(2);API in a non-Spring environment
When using the SOFARPC API directly in a non-Spring environment, you can call the setRetries method of ConsumerConfig to set the number of retries:
ConsumerConfig<RetriesService> consumerConfig =new ConsumerConfig<RetriesService>();
consumerConfig.setRetries(2);