文档

调用重试

更新时间:

SOFARPC 支持进行框架层面的重试策略,前提是集群模式为 FailOver(SOFARPC 默认为 FailOver 模式)。重试只有在服务端的框架层面异常或超时异常时才会发起,不会对业务抛出的异常进行重试。默认情况下 SOFARPC 不进行任何重试。

重要

超时异常虽然可以重试,但是需要服务端保证业务的幂等性,否则可能会有风险。

XML 方式

如果使用 XML 方式订阅服务,可以设置 sofa:global-attrsretries 参数来设置重试次数:

<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 方式

如果是使用 Annotation 的方式,可以通过设置 @SofaReferenceBinding 注解的 retries 属性来设置重试次数:

@SofaReference(binding =@SofaReferenceBinding(bindingType ="bolt", retries =2))
private SampleService sampleService;

Spring 环境下 API 方式

如果是在 Spring 环境下用 API 的方式,可以调用 BoltBindingParamsetRetries 方法来设置重试次数:

BoltBindingParam boltBindingParam =new BoltBindingParam();
boltBindingParam.setRetries(2);

非 Spring 环境下 API 方式

如果是在非 Spring 环境下直接使用 SOFARPC 的裸 API 的方式,可以通过调用 ConsumerConfigsetRetries 方法来设置重试次数:

ConsumerConfig<RetriesService> consumerConfig =new ConsumerConfig<RetriesService>();
consumerConfig.setRetries(2);
  • 本页导读 (0)
文档反馈