Unlike ordinary RPC frameworks, Dubbo, as a microservices framework, provides very flexible protocol support and does not bind to a single communication protocol. Therefore, you can publish multiple RPC protocols simultaneously in one process and call different RPC protocols. Next, we will detail the specific use cases and methods for multiple protocols.
There are many scenarios where different protocols may be needed, including security, performance, and interaction with third-party systems. This article does not analyze specific business requirements but instead explores the multi-protocol capabilities provided by the Dubbo framework:
If using Spring Boot, you can modify application.yml or application.properties as follows:
dubbo:
protocols:
dubbo-id:
name: dubbo
port: 20880
tri-id:
name: tri
port: 50051
For Spring XML:
<dubbo:protocol id="dubbo-id" name="dubbo" port="20880"/>
<dubbo:protocol id="triple-id" name="tri" port="50051"/>
Next, configure the service (by default, the service will be published to all protocol configurations above):
@DubboService(protocol="dubbo-id,triple-id")
private DemoServiceImpl implements DemoService {}
If using Spring Boot, modify application.yml or application.properties as follows:
dubbo:
protocols:
dubbo-id:
name: dubbo
port: 20880
tri-id:
name: tri
port: 50051
Next, configure different protocol references for different services:
@DubboService(protocol="dubbo-id")
private DemoServiceImpl implements DemoService {}
@DubboService(protocol="triple-id")
private GreetingServiceImpl implements GreetingService {}
For consumers, simply specify the protocol keyword when declaring the reference:
@DubboReference(protocol="dubbo")
private DemoService demoService;
@DubboReference(protocol="tri")
private GreetingService greetingService;
Multi-protocol publishing means providing multiple protocol access methods for the same service. Multi-protocol can be any combination of two or more protocols, such as the configuration below which simultaneously publishes both dubbo and triple protocols:
dubbo:
protocols:
tri:
name: tri
port: 50051
dubbo:
name: dubbo
port: 20880
Based on the configuration above, if the application has the service DemoService, it can be accessed via both the dubbo and triple protocols. The working principle diagram is as follows:
For consumers, if the user has not specified, the framework will automatically select the dubbo
protocol by default. The Dubbo framework supports configuring which protocol accesses the service, such as @DubboReference(protocol="tri")
, or specifying a global default in the application.yml configuration file:
dubbo:
consumer:
protocol: tri
In addition to the methods of publishing multiple ports and registering multiple URLs to the registration center, for the built-in dubbo and triple protocols, the framework provides the ability to publish both protocols on a single port simultaneously. This is an important capability for long-time users, as it allows users utilizing the dubbo protocol to additionally publish the triple protocol without adding any burden. Once all applications realize multi-protocol publishing, we can set consumers to initiate calls via the triple protocol.
The basic configuration for single-port multi-protocol is as follows:
dubbo:
protocol:
name: dubbo
ext-protocol: tri