网络传输扩展

扩展说明

远程通讯的服务器及客户端传输实现。

扩展接口

  • com.alibaba.dubbo.remoting.Transporter
  • com.alibaba.dubbo.remoting.Server
  • com.alibaba.dubbo.remoting.Client

    扩展配置

  1. <!-- 服务器和客户端使用相同的传输实现 -->
  2. <dubbo:protocol transporter="xxx" />
  3. <!-- 服务器和客户端使用不同的传输实现 -->
  4. <dubbo:protocol server="xxx" client="xxx" />
  5. <!-- 缺省值设置,当<dubbo:protocol>没有配置transporter/server/client属性时,使用此配置 -->
  6. <dubbo:provider transporter="xxx" server="xxx" client="xxx" />

已知扩展

  • com.alibaba.dubbo.remoting.transport.transporter.netty.NettyTransporter
  • com.alibaba.dubbo.remoting.transport.transporter.mina.MinaTransporter
  • com.alibaba.dubbo.remoting.transport.transporter.grizzly.GrizzlyTransporter

    扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxTransporter.java (实现Transporter接口)
  7. |-XxxServer.java (实现Server接口)
  8. |-XxxClient.java (实现Client接口)
  9. |-resources
  10. |-META-INF
  11. |-dubbo
  12. |-com.alibaba.dubbo.remoting.Transporter (纯文本文件,内容为:xxx=com.xxx.XxxTransporter)

XxxTransporter.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.remoting.Transporter;
  3. public class XxxTransporter implements Transporter {
  4. public Server bind(URL url, ChannelHandler handler) throws RemotingException {
  5. return new XxxServer(url, handler);
  6. }
  7. public Client connect(URL url, ChannelHandler handler) throws RemotingException {
  8. return new XxxClient(url, handler);
  9. }
  10. }

XxxServer.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.remoting.transport.transporter.AbstractServer;
  3. public class XxxServer extends AbstractServer {
  4. public XxxServer(URL url, ChannelHandler handler) throws RemotingException{
  5. super(url, handler);
  6. }
  7. protected void doOpen() throws Throwable {
  8. // ...
  9. }
  10. protected void doClose() throws Throwable {
  11. // ...
  12. }
  13. public Collection<Channel> getChannels() {
  14. // ...
  15. }
  16. public Channel getChannel(InetSocketAddress remoteAddress) {
  17. // ...
  18. }
  19. }

XxxClient.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.remoting.transport.transporter.AbstractClient;
  3. public class XxxClient extends AbstractClient {
  4. public XxxServer(URL url, ChannelHandler handler) throws RemotingException{
  5. super(url, handler);
  6. }
  7. protected void doOpen() throws Throwable {
  8. // ...
  9. }
  10. protected void doClose() throws Throwable {
  11. // ...
  12. }
  13. protected void doConnect() throws Throwable {
  14. // ...
  15. }
  16. public Channel getChannel() {
  17. // ...
  18. }
  19. }

META-INF/dubbo/com.alibaba.dubbo.remoting.Transporter:

  1. xxx=com.xxx.XxxTransporter

原文: http://dubbo.apache.org/#!/docs/dev/impls/remoting.md?lang=zh-cn