Service publishing and reference

Update time: 2019-06-21

The basic configuration for SOFARPC service publishing and reference is described in the “Programming Interface” chapter. Here are some of the features of service publishing and referencing.

One service publishes multiple protocols

In SOFARPC, a service can be published as multiple protocols, which allows the callers to call the service provider using different protocols.

If you use the Java API, you can build multiple ServerConfigs as follows to set different protocols for different ServerConfigs and then assign these ServerConfigs to ProviderConfig:

 List<ServerConfig> serverConfigs = new ArrayList<ServerConfig>();

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

<sofa:service ref="sampleFacadeImpl" interface="">

If you use annotation, add multiple bindings in @SofaService:

@SofaService (
        interfaceType = SampleService.class,
        bindings = {
                @SofaServiceBinding(bindingType = "rest"),
                @SofaServiceBinding(bindingType = "bolt")
public class SampleServiceImpl implements SampleService {
    // ...

One service registers multiple registry centers

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

List<RegistryConfig> registryConfigs = new ArrayList<RegistryConfig>();

Method-level parameter settings

In the Java API mode, you can set the corresponding parameters by calling the set method of the MethodConfig object, as shown below:

MethodConfig methodConfigA = new MethodConfig();
MethodConfig methodConfigB = new MethodConfig();

List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
providerConfig.setMethods(methodConfigs); //server settings
consumerConfig.setMethods(methodConfigs); //Client settings

In the XML mode, you can use the <sofa:method> tag in the corresponding binding to set the corresponding parameters:

<sofa:reference id="personReferenceBolt" interface="">
        <sofa:global-attrs timeout="3000" address-wait-time="2000"/> <!-- Call timeout; address wait time. -->
        <sofa:route target-url=""/> <!-- Directly connected address -->
        <sofa:method name="sayName" timeout="3000"/> <!-- Method level configuration -->

<sofa:service ref="sampleFacadeImpl" interface="">
        <sofa:global-attrs timeout="3000"/>
        <sofa:method name="sayName" timeout="2000"/>

Currently, the Annotation mode does not support setting method-level parameters, which will be available in the future versions.

Configuration overrides

Both the service provider and service caller support some configurations in SOFARPC, such as the calling timeout attribute. The priority of these configurations is as follows:

Thread call-level settings >> Service caller method-level settings >> Service caller reference-level settings >> Service provider method-level settings >> Service provider service-level settings