Overview ---- Dubbo Invoker service discovery, clustering, load balancing, routing system

Invoker, load network calling component, according to the underlying network communications and lazy, Invoker is responsible for service calls, natural and routing (such as clustering) and other functions closely related to the start of this section to control the whole system at Dubbo service calls, service discovery, clustering, load balancing, routing mechanism, the entire body of knowledge, combing finishing Dubbo Invoker entire class diagram as follows:

Write pictures described here
The main group has the following interfaces

  1. Invocation (call context)
  • Invocation:
    • String getMethodName () method gets called names.
    • Class <?> [] GetParameterTypes ( )
      Gets the called method parameter list (parameter type)
    • Object [] getArguments () Gets the value of the array parameter called method.
    • Map <String, String> getAttachments () for additional properties.
    • String getAttachment (String key) the attribute values ​​to obtain additional key.
    • String getAttachment (String key, String defaultValue) The key to obtain additional attribute, if not present, the default value.
    • Invoker <?> GetInvoker () Gets the current invoker.
  • RpcInvocation rpc call service implementation class Invocation calling context, is to use a Bean store parameters for the current method call, its essence is just an ordinary Bean.
  • MockInvocation a mock test unit.
  • rpc DecodeableRpcInvocation band decoding function call context is mainly to achieve the service request from the RPC call by parsing the binary stream (binaries) to give RPC service calling context (metadata method call).
  1. Invoker service call, a call Dubbo abstract services.

Invoer abstract interface, inherited from com.alibaba.dubbo.common.Node Interface

  • Node:
    • URL getUrl (); fetching URL, in dubbo, the registry, service providers, service consumers, the monitoring center so using the URL below.
    • boolean isAvailable (): determining whether available.
    • void destroy (): Resource destroyed.
  • Invoker:
    • Class getInterface (): Gets the interface of the service provider. Result invoke (Invocation invocation) throws RpcException: call service, invocation result is returned.
  • AbstractInvoker Invoker default implementation (template class) This method is mainly achieved public Result invoke (Invocation inv) throws RpcException, perform a basic process definition execution invoker (template), and personalized depending on the implementation subclasses (different protocols) perform their task. Abstract methods: protected abstract Result doInvoke (Invocation invocation) throws Throwable, embodied in the later analysis.
  • DubboInvoker dubbo agreement caller implementation.
  • InjvmInvoker injvm agreement calls for a specific implementation (local agreement)
    • AbstractClusterInvoker cluster model call the template of this class is to call the template class Dubbo cluster model, the topic addresses a service that has multiple service providers, this time how to select a specific message consumer end service provider to invoke a service. This class needs to organize multiple service providers, service providers and select a call in accordance with the specified algorithm.
  • AvailableClusterInvoker by <dubbo: service cluster = "available" ... /> or <dubbo: reference cluster = "available" ... /> cluster strategy: Always choose the first available service provider.
  • BroadcastClusterInvoker by <dubbo: service cluster = "broadcast" ... /> or <dubbo: reference cluster = "broadcast" ... /> cluster strategy: broadcast mode, sends request to all service providers, any call fails it is considered a failure.
  • FailbackClusterInvoker by <dubbo: service cluster = "failback" ... /> or <dubbo: reference cluster = "failback" ... /> cluster strategy: After the service call failed, timed retry, retry count wireless, the heavy, test frequency: 5s. And will not switch service providers.
  • FailfastClusterInvoker by <dubbo: service cluster = "failfast" ... /> or <dubbo: reference cluster = "failfast" ... /> cluster strategy: After the service call, fail-fast, direct throw an exception, not retry , are not subject to the constraints of retries parameters for add, modify class operation.
  • FailoverClusterInvoker by <dubbo: service cluster = "failover" ... /> or <dubbo: reference cluster = "failover" ... /> cluster strategy: After the service call, if a failure occurs, retry other service providers, the default retry two times, performed a total of three times the number of retries configured by retries, dubbo cluster default.
  • FailsafeClusterInvoker by <dubbo: service cluster = "failsafe" ... /> or <dubbo: reference cluster = "failsafe" ... /> cluster strategy: After the service call, only print the error log, and then return directly.
  • ForkingClusterInvoker
    by <dubbo: service cluster = "forking " ... /> or <dubbo: reference cluster = "forking " ... /> cluster strategy: concurrent calls to multiple service providers, take the first result returned. The number of those who can provide through the Service Desk forks set of concurrent calls.

More cluster strategy, can refer /dubbo-cluster/src/main/resources/META-/com.alibaba.dubbo.rpc.cluster.Cluster file.

Write pictures described here

  1. When LoadBalance clustering algorithm load when a service has multiple service providers, load balancing algorithm to select the service provider's consumer side during service calls. Interface defined for LoadBalance: <T> Invoker select (List <Invoker> invokers, URL url, Invocation invocation) throws RpcException;
  • ConsistentHashLoadBalance by <dubbo: service loadbalance = "consistenthash" ... /> or <dubbo: provider loadbalance = "consistenthash" ... /> load balancing algorithm: Consistency Hash algorithm, AbstractClusterInvoker from multiple service providers It is called when selecting a service provider.
  • LeastActiveLoadBalance by <dubbo: service loadbalance = "leastactive" ... /> or <dubbo: provider loadbalance = "leastactive" ... /> load balancing algorithms: Minimum active call.
  • RandomLoadBalance by <dubbo: service loadbalance = "random" ... /> or <dubbo: service loadbalance = "random" ... /> load balancing algorithm: random, if the weight (the weight, the higher the chance)
  • RoundRobinLoadBalance by <dubbo: service loadbalance = "roundrobin" ... /> or <dubbo: provider loadbalance = "roundrobin" ... /> load balancing algorithms: WRR algorithm.
  • Directory (directory service, Invoker directory service) that interface the main role is to service providers of directory services to manage multiple service providers.
  • Directory
    • Class <T> getInterface () Gets the service interface category.
    • List <Invoker <T >> list (Invocation invocation) throws RpcException get the current context of all the service providers of the service according to the invocation.

4.2 AbstractDirectory abstract column directory service implementation (template class)

4.3 StaticDirectory static directory services

The so-called static directory services is to specify a set of service providers, the directory service instances in their life cycle, these service providers will only return when creating StaticDirectory.

  • RegistryDirectory Active Directory Service (registry-based), dynamic access to discovery services provided, the default message consumer does not specify a particular service provider URL from the registry, it will subscribe to a service provider services to the registry (Registry providers monitor directory), use RegistryDirectory automatically obtain a list of registry server.
  • Router routing function according to news consumers URL, or a combination of routing expressions JS engine, select Invoker comply with routing rules from the Directory, and then performs load balancing algorithm.
  • Router
    • URL getUrl (); Gets the message consumer URL.
    • 2, <T> List <Invoker <T >> route (List <Invoker <T >> invokers, URL url, Invocation invocation) throws RpcException according to news consumers URL, selection of optimal Invokers from invokers in.
  • ConditionRouter routing conditional expression based implementation.
  • ScriptRouter achieve routing JS Engine.

Invoker implement a single, e.g. DubboInvoker, InJVMInvoker underlying network call channel transmission request command (Oneway, synchronous, asynchronous invocation), which is devoted to the details of the underlying network focuses on networks in a subsequent chapter, the next chapter, the main source from angle analysis of clustering, load balancing, dynamic routing, directory services (RegistryDirectory) implementation details.


Author: Ding Wei, "RocketMQ Technology Insider" author, RocketMQ community preacher, public number: Middleware interest circle defenders, has been published a set of Java source code analysis, Java and contracting (JUC), Netty, Mycat, Dubbo, RocketMQ, Mybatis and other source columns. Click on the link can join middleware knowledge of the planet , to explore high concurrency, distributed service architecture, AC source.

Here Insert Picture Description

Guess you like

Origin juejin.im/post/5e04ba53518825123b1aa61b