When you use the BOLT protocol for communication, the default timeout for SOFARPC is 3000 ms. You can set the timeout at the service or method level. All SOFARPC timeouts are specified in milliseconds.
Service dimension
To set a timeout at the service level, set the timeout parameter when you publish a service.
XML method
If you reference a service using XML, set the timeout property of the <sofa:global-attrs> tag within the <sofa:binding.bolt> tag.
<sofa:reference interface="com.example.demo.SampleService" id="sampleService">
<sofa:binding.bolt>
<sofa:global-attrs timeout="2000"/>
</sofa:binding.bolt>
</sofa:reference>Annotation method
If you reference a service using an annotation, set the timeout property of @SofaReferenceBinding.
@SofaReference(binding =@SofaReferenceBinding(bindingType ="bolt", timeout =2000))
private SampleService sampleService;Spring environment API method
If you reference a service in a Spring or Spring Boot environment, set the timeout property of BoltBindingParam.
BoltBindingParam boltBindingParam =new BoltBindingParam();
boltBindingParam.setTimeout(2000)Non-Spring environment API method
If you reference a service using the native SOFARPC API in a non-Spring environment, set the timeout property of ConsumerConfig.
ConsumerConfig<SampleService> consumerConfig =new ConsumerConfig<SampleService>()
.setInterfaceId(SampleService.class.getName())
.setRegistry(registryConfig)
.setProtocol("bolt")
.setTimeout(2000);Method Dimension
You can set a timeout for a specific method in a service. The method-level timeout takes precedence over the service-level timeout. If a method-level timeout is not set, the service-level timeout is used.
XML method
If you reference a service using XML, set the timeout property of the corresponding <sofa:method> tag.
<sofa:reference interface="com.example.demo.SampleService" id="sampleService">
<sofa:binding.bolt>
<sofa:method name="hello" timeout="2000"/>
</sofa:binding.bolt>
</sofa:reference>Annotation method
Setting method-level timeouts using annotations is not currently supported.
Spring environment API method
If you reference a service in a Spring or Spring Boot environment, set the timeout property of RpcBindingMethodInfo.
BoltBindingParam boltBindingParam =new BoltBindingParam();
RpcBindingMethodInfo rpcBindingMethodInfo =new RpcBindingMethodInfo();
rpcBindingMethodInfo.setName("hello");
rpcBindingMethodInfo.setTimeout(2000);
List<RpcBindingMethodInfo> rpcBindingMethodInfos =new ArrayList<>();
rpcBindingMethodInfos.add(rpcBindingMethodInfo);
boltBindingParam.setMethodInfos(rpcBindingMethodInfos);Non-Spring environment API method
If you reference a service using the native SOFARPC API in a non-Spring environment, set the timeout property of MethodConfig.
MethodConfig methodConfig =new MethodConfig();
methodConfig.setName("hello");
methodConfig.setTimeout(2000);
List<MethodConfig> methodConfigs =new ArrayList<MethodConfig>();
methodConfigs.add(methodConfig);
ConsumerConfig<SampleService> consumerConfig =new ConsumerConfig<SampleService>()
.setInterfaceId(SampleService.class.getName())
.setRegistry(registryConfig)
.setProtocol("bolt")
.setMethods(methodConfigs);