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
ServerConfigobjects and set a different protocol for each one. Then, assign theseServerConfigobjects to theProviderConfig.List<ServerConfig> serverConfigs =new ArrayList<ServerConfig>(); serverConfigs.add(serverConfigA); serverConfigs.add(serverConfigB); providerConfig.setServer(serverConfigs);XML method
Simply add multiple
bindingelements 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
bindingelements in the@SofaServiceannotation:NoteIf 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{ // ... }
Is this page helpful?