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:
For Spring XML:
Next, configure the service (by default, the service will be published to all protocol configurations above):
If using Spring Boot, modify application.yml or application.properties as follows:
Next, configure different protocol references for different services:
For consumers, simply specify the protocol keyword when declaring the reference:
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:
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:
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: