Publish a service with multiple protocols

Updated at:

In SOFARPC, a single service can be published with multiple protocols. Clients can then invoke the service using different protocols. The following methods are available:

  • Using the Java API

    Build multiple ServerConfig objects and set a different protocol for each one. Then, assign these ServerConfig objects to the ProviderConfig.

    List<ServerConfig> serverConfigs =new ArrayList<ServerConfig>();
    serverConfigs.add(serverConfigA);
    serverConfigs.add(serverConfigB);
    providerConfig.setServer(serverConfigs);
  • XML method

    Simply add multiple binding elements to the <sofa:service> tag:

    <sofa:service ref="sampleFacadeImpl" interface="com.alipay.sofa.rpc.bean.SampleFacade">
        <sofa:binding.bolt/>
        <sofa:binding.rest/>
        <sofa:binding.dubbo/>
    </sofa:service>
  • Annotation methods

    Simply add multiple binding elements in the @SofaService annotation:

    Note

    If you use the REST protocol, add a path to the interface.

    @SofaService(
          interfaceType =SampleService.class,
          bindings ={
    @SofaServiceBinding(bindingType ="rest"),// If you use the REST protocol, add a path to the interface.
    @SofaServiceBinding(bindingType ="bolt")
    }
    )
    public class SampleServiceImpl implements SampleService{
    // ...
    }