9.15. 消息派发扩展

通道信息派发器,用于指定线程池模型。

扩展接口

org.apache.dubbo.remoting.Dispatcher

扩展配置

<dubbo:protocol dispatcher="xxx" />
<!-- 缺省值设置,当<dubbo:protocol>没有配置dispatcher属性时,使用此配置 -->
<dubbo:provider dispatcher="xxx" />

已知扩展

  • org.apache.dubbo.remoting.transport.dispatcher.all.AllDispatcher
  • org.apache.dubbo.remoting.transport.dispatcher.direct.DirectDispatcher
  • org.apache.dubbo.remoting.transport.dispatcher.message.MessageOnlyDispatcher
  • org.apache.dubbo.remoting.transport.dispatcher.execution.ExecutionDispatcher
  • org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedDispatcher

扩展示例

  • Maven 项目结构:
    src
     |-main
        |-java
            |-com
                |-xxx
                    |-XxxDispatcher.java (实现Dispatcher接口)
        |-resources
            |-META-INF
                |-dubbo
                    |-org.apache.dubbo.remoting.Dispatcher (纯文本文件,内容为:xxx=com.xxx.XxxDispatcher)
    
  • XxxDispatcher.java:
    package com.xxx;
    import org.apache.dubbo.remoting.Dispatcher;
    public class XxxDispatcher implements Dispatcher {
        public Group lookup(URL url) {
            // ...
        }
    }
    
  • META-INF/dubbo/org.apache.dubbo.remoting.Dispatcher:
    xxx=com.xxx.XxxDispatcher
    
下一节:服务提供方线程池实现策略,当服务器收到一个请求时,需要在线程池中创建一个线程去执行服务提供方业务逻辑。