Taking the RPC Protocol Plugin
as an example, this section demonstrates how to use the SPI plugin provided by Dubbo to provide a custom RPC protocol implementation. If you want to understand how the SPI mechanism works and the list of built-in SPI extension points in the framework, please refer to the Reference Manual - SPI Extension.
Provide a Java class that implements the org.apache.dubbo.rpc.Protocol
interface.
package com.spi.demo;
import org.apache.dubbo.rpc.Protocol;
@Activate
public class CustomizedProtocol implements Protocol {
// ...
}
Add a org.apache.dubbo.rpc.Protocol
file in the application’s resources/META-INF/services/
directory, and include the following configuration in the file:
customized=com.spi.demo.CustomizedProtocol
resources/META-INF/services/org.apache.dubbo.rpc.Protocol
in this example.key=value
format, where key
can be defined arbitrarily, but it is recommended to add a specific prefix to avoid name collisions with Dubbo’s built-in implementations; value
must be the full path name of the implementation class.Modify the protocol configuration in the application to tell the Dubbo framework to use the custom protocol:
# For Spring Boot, you can modify application.yml or application.properties
dubbo
protocol
name: customized
or
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("cutomized");
If you want to see more complete examples, please refer to other examples in this directory: