All Products
Document Center

Special Service Reference and Registration

Last Updated: Aug 17, 2020

This topic describes special service reference, registration and configuration priority.

Service reference with multiple protocols

In SOFARPC, a service can be published for multiple protocols, so that the caller can call the service provider through different protocols.

If you use the Java API, you can construct multiple ServerConfigs as follows, which are set with different protocols, and then assign them to ProviderConfig:

  1. List<ServerConfig> serverConfigs = new ArrayList<ServerConfig>();
  2. serverConfigs.add(serverConfigA);
  3. serverConfigs.add(serverConfigB);
  4. providerConfig.setServer(serverConfigs);

If you use the XML, create multiple bindings in the <sofa:service> tag:

  1. <sofa:service ref="sampleFacadeImpl" interface="">
  2. <sofa:binding.bolt/>
  3. <>
  4. <sofa:binding.dubbo/>
  5. </sofa:service>

If you use the Annotation, create multiple bindings in @SofaService:

  1. @SofaService(
  2. interfaceType = SampleService.class,
  3. bindings = {
  4. @SofaServiceBinding(bindingType = "rest"),
  5. @SofaServiceBinding(bindingType = "bolt")
  6. }
  7. )
  8. public class SampleServiceImpl implements SampleService {
  9. // ...
  10. }

Configuration Priority

Some configurations in SOFARPC can be set at the service provider or at the service caller, such as the calling timeout period. The priority of these configurations is listed below from high to low order:

  • thread invocation configuration
  • Service Reference Side
    • method configuration
    • Reference configuration
  • Service Provider
    • method configuration
    • Service configuration

Register a service in multiple registries

If you use the API, build multiple RegistryConfigs and assign them to ProviderConfig:

  1. List<RegistryConfig> registryConfigs = new ArrayList<RegistryConfig>();
  2. registryConfigs.add(registryA);
  3. registryConfigs.add(registryB);
  4. providerConfig.setRegistry(registryConfigs);

Configure method parameters

In the Java API, you can call the setter method corresponding to the MethodConfig object to configure the corresponding parameters:

  1. MethodConfig methodConfigA = new MethodConfig();
  2. MethodConfig methodConfigB = new MethodConfig();
  3. List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
  4. methodConfigs.add(methodConfigA);
  5. methodConfigs.add(methodConfigB);
  6. providerConfig.setMethods(methodConfigs); //Server configuration
  7. consumerConfig.setMethods(methodConfigs); //Client configuration

In the XML, you can use the <sofa:method> tag in the corresponding binding to configure the corresponding parameter:

  1. <sofa:reference id="personReferenceBolt" interface="">
  2. <sofa:binding.bolt>
  3. <sofa:global-attrs timeout="3000" address-wait-time="2000"/> <! -- Calling timeout period; time of waiting for the address to be obtained.-->
  4. <sofa:route target-url=""/> <! -- Direct connection URL -->
  5. <sofa:method name="sayName" timeout="3000"/> <! -- Method-level configuration -->
  6. </sofa:binding.bolt>
  7. </sofa:reference>
  8. <sofa:service ref="sampleFacadeImpl" interface="">
  9. <sofa:binding.bolt>
  10. <sofa:global-attrs timeout="3000"/>
  11. <sofa:method name="sayName" timeout="2000"/>
  12. </sofa:binding.bolt>
  13. </sofa:service>

Currently, you cannot set method parameters in the Annotation mode. This will be supported in later versions.