Under the BOLT communication protocol, the timeout period in SOFARPC is 3s by default. You can set the timeout period in the service or method configuration when referencing a service. The timeout period is set in milliseconds (ms).
Service-level configuration
To set the timeout period in the service configuration when publishing a service, you can set the timeout parameter to the corresponding value. There are 3 configuration ways as follows:
- XML: When you reference a service through the XML mode, set the
timeout
attribute of<sofa:global-attrs>
in 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: When you reference a service through the Annotation mode, set the
timeout
attribute of@SofaReferenceBinding
.@SofaReference(binding = @SofaReferenceBinding(bindingType = "bolt", timeout = 2000))
private SampleService sampleService;
- API:
- configure as a Spring project: When you reference a service in a Spring or Spring Boot environment, set the
timeout
attribute ofBoltBindingParam
.BoltBindingParam boltBindingParam = new BoltBindingParam();
boltBindingParam.setTimeout(2000)
- configure without a Spring framework: When you reference a service by using a raw API of SOFARPC in a non-Spring environment, set the
timeout
attribute ofConsumerConfig
.ConsumerConfig<SampleService> consumerConfig = new ConsumerConfig<SampleService>()
.setInterfaceId(SampleService.class.getName())
.setRegistry(registryConfig)
.setProtocol("bolt")
.setTimeout(2000);
- configure as a Spring project: When you reference a service in a Spring or Spring Boot environment, set the
Method-level configuration
The timeout configuration in method level has a higher priority than that at service level.The absence of configuration at method level will make the configuration at service level effective. There are 3 configuration ways as follows:
XML: When you reference a service through the XML mode, set the
timeout
attribute of the<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: Currently, you cannot set the timeout period at the method level in the Annotation mode.
API:
configure as a Spring project: When you reference a service in a Spring or Spring Boot environment, set the
timeout
attribute ofRpcBindingMethodInfo
.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);
configure without a Spring framework: When you reference a service by using a raw API of SOFARPC in a non-Spring environment, set the
timeout
attribute ofMethodConfig
.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);