Dubbo3 路由拓展

2022-04-22 11:53 更新

擴展說明

從多個服務提供方中選擇一個進行調用。

擴展接口

  • 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 (實現(xiàn)RouterFactory接口)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.rpc.cluster.RouterFactory (純文本文件,內容為: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


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號