七Dubbo各模块的层次核心接口及组件类--4Cluster层--Cluster-Directory-Router

七Dubbo各模块的层次核心接口及组件类--4Cluster层--Cluster-Directory-Router

7.4 Cluster(Cluster模块)

路由层:封装多个提供者的路由及负载均衡,并桥接注册中心,以invoker为中心。

模块 Dubbo层 各层核心接口
Service ServiceBean ReferanceBean
dubbo-config Config ServiceConfig ReferanceConfig
dubbo-RPC Proxy ServiceProxy ProxyFactory
dubbo-registry Registry RegistryFactory Registry RegistryService
dubbo-cluster Cluster Cluster Directory Router LoadBalance
dubbo-monitor Monitor
dubbo-RPC Protocol Filter Invoker Prococol Exporter
dubbo-remoting Exchange Exchanger ExchangeChannel ExchangeClient ExchangeServer
Transport Transport Channel Client Server Codec
dubbo-common Serialize

集群层,是对于多个provider时,consumer端调用场景的抽象,是dubbo集群容错的抽象层。

7.4.1 Cluster

image-20220830132223959

image-20221212163010538

7.4.2 Directory

image-20220830123404603

Directory 代表多个 Invoker,可以把它看成 List<Invoker> ,但与 List 不同的是,它的值可能是动态变化的,比如注册中心推送变更。

notifyListener是监听机制。

public interface Directory<T> extends Node {

    /**
     * get service type.
     */
    Class<T> getInterface();

    /**
     * list invokers.
     */
    List<Invoker<T>> list(Invocation invocation) throws RpcException;

}

7.4.3 Router

image-20220830132523365

public interface Router extends Comparable<Router> {

 //get the router url.
    URL getUrl();

    /**
     * route.
     *
     * @param invokers
     * @param url        refer url
     * @param invocation
     * @return routed invokers
     * @throws RpcException
     */
    <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException;

}
posted @ 2023-03-13 14:54  LeasonXue  阅读(41)  评论(0)    收藏  举报