路由擴充

擴充說明

從多個服務提供者中選擇一個進行呼叫。

擴充埠

  • org.apache.dubbo.rpc.cluster.RouterFactory
  • org.apache.dubbo.rpc.cluster.Router

已知擴充

  • org.apache.dubbo.rpc.cluster.router.ScriptRouterFactory
  • org.apache.dubbo.rpc.cluster.router.FileRouterFactory
  • org.apache.dubbo.rpc.cluster.router.condition.config.AppRouterFactory
  • org.apache.dubbo.rpc.cluster.CacheableRouterFactory
  • org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory
  • org.apache.dubbo.rpc.cluster.router.mock.MockRouterFactory
  • org.apache.dubbo.rpc.cluster.router.condition.config.ServiceRouterFactory
  • org.apache.dubbo.rpc.cluster.router.tag.TagRouterFactory

擴充範例

Maven 專案結構

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxRouterFactory.java (implements RouterFactory interface)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.rpc.cluster.RouterFactory (plain text file, content: xxx=com.xxx.XxxRouterFactory)

XxxRouterFactory.java

package com.xxx;
 
import org.apache.dubbo.rpc.cluster.RouterFactory;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.RpcException;
 
public class XxxRouterFactory implements RouterFactory {
    public Router getRouter(URL url) {
        //...
    }
}

META-INF/dubbo/org.apache.dubbo.rpc.cluster.RouterFactory

xxx=com.xxx.XxxRouterFactory

最後修改日期:2023 年 1 月 2 日:增強英文文件 (#1798) (95a9f4f6c1c)