org.apache.dubbo.rpc.Protocol
SPI.In the Communication Protocol chapter, we learned about several core RPC protocols built into Dubbo: dubbo
, rest
, and tri
, and how to use them. This article explains how to provide a custom RPC protocol implementation by extending the org.apache.dubbo.rpc.Protocol
SPI.
There are two ways to create a private protocol: the first is to wrap the existing protocol and add specific business logic. The second is to completely customize a protocol. The former is simpler to implement and is widely used in dubbo
, such as ProtocolFilterWrapper
, QosProtocolWrapper
, and ProtocolListenerWrapper
. The latter is relatively complex but offers maximum flexibility; for instance, the built-in protocols dubbo
and triple
in the Dubbo framework fall under this implementation style.
For the complete source code of this example, refer to dubbo-samples-extensibility. In addition to this example, many Protocol implementations in the core Dubbo repository apache/dubbo and the extension library apache/dubbo-spi-extensions can also serve as extension references:
Implement a custom protocol edubbo
based on the existing dubbo
protocol.
The edubbo
protocol is implemented by wrapping the dubbo
protocol.
Add the following configuration in the resources/META-INF/dubbo/org.apache.dubbo.rpc.Protocol
file:
Add the following configuration in the resources/META-INF/dubbo/org.apache.dubbo.rpc.Protocol
file:
Add the following configuration in the resources/application.properties
file:
Add the following configuration in the resources/application.properties
file:
Run the task using local IDE, the results are as follows: