The service consumer initiates the request

When the consumer of a service references a remote service, the application of the service is configured in Spring as follows:

<dubbo:referenceid= “demoService” interface= “com.alibaba.dubbo.demo.DemoServ ice” />

SayHello (” World! ),

1. Pass the method name method argument to the Invoke side of InvokerInvocationHandler

For the toString, hashCode, and equals methods of Object, call invoker directly.

Do methods on Object need to be called remotely here? Is the call error better than the default processing?

The remote Invocation layer is centered around the Invocation Result, where the RpcInvocation object is built as an Invoker Invocation based on the method to be invoked and the parameters passed in

MockClusterInvoker provides three invocation strategies based on parameters

Call FailoverClusterInvoker without mock

Force mock, invoke mock

FailoverClusterInvoker fails at mock

3. FailoverClusterInvoker invokes the policy by default

Invoker objects for all subscribed service providers are found through the directory service

The routing service filters Invokers selected for invocation based on policy

Select an Invoker using the load balancing policy LoadBalance

4. Invocation selected Invoker. Inoker (Invocation)

Through the listener chain, none by default

Through the filter chain, a lot is built in

DubboInvoker to perform a remote call

5.      DubboInvoker

Based on the URL, that is, based on the long connection of the service provider, there is an interaction layer object called ExchangeClient here

Determine whether the remote invocation type is synchronous, asynchronous, or Oneway

ExchangeClient makes remote calls, and the underlying remoting is not described here

Get the call result:

Oneway returns empty RpcResult

Asynchronous, directly returns null RpcResult, ResponseFuture callback

ResponseFuture mode synchronous to asynchronous and waits for the response to return

 

The service provider receives the invocation request

Similarly, we also start to analyze the DubboProtocol layer of RPC call layer, and do not analyze the data receiving reverse sequence of remoting and other processes of communication layer.

DubboProtocol’s requestHandler is an implementation of ExchangeHandler, which is a callback to data received by the remoting layer.

The requesthandler. replay method receives the request message; only the remote Invocation message Invocation is handled here.

1. Through the Invocation service name and port of the serviceKey = com. Alibaba. Dubbo. Demo. DemoService: 20880, DubboExporter, which operates exposed services from DubboProtocol’s exproterMap, returns invoker from DubboExporter

2. Pass through the filter chain

3. Go through the listener chain

GetInvoker (demoService, demoservice.class, registryUrl) is created by the ProxyFactory proxyfactory.getinvoker (demoService, demoservice.class, registryUrl).

Call the demoService instance method and return the result wrapped as RpcResult

5. The exchange layer constructs the Response and sends the Response to the caller through the Remoting layer encoding transmission

 

The underlying communication that a service consumer initiates a remote invocation

\

 

The underlying communication in which a service provider receives a request and responds

\

\

One: Provider Provider





\

ClassPathXmlApplicationContext < init > (method)

-> ClassPathXmlApplicationContext refresh()

-> ClassPathXmlApplicationContext finishRefresh()

-> AbstractApplicationContext publishEvent()

-> ServiceBean onApplicationEvent()

-> ServiceConfig doExport()

Application Provider Module Protocol Registry Service Reference Consume

\

-> ServiceConfig doExportUrls # Export URL, obtain registry RegistryConfig

# registry: a registry: / / 10.199.101.228:2181 / com. Alibaba. Dubbo. Registry. RegistryService? Application = demo&backup = 10.199.101.227:2181,10.199. 101.229:2181 & dubbo = 2.4.9 & pid = 8045 & registry = zookeeper&timestamp = 149154 6077803

\

-> ServiceConfig doExportUrlsFor1Protocol()

# need to expose dubbo: / / 10.199.66.242:20880 / com. Unj. Dubbotest. Provider. DemoService? Anyhost = true&application = dubbo_demo_provider & dubbo = 2.4.9 & interface = com. Unj. Dubbotest. Provider. DemoService&methods = sayHel Lo, getUsers&pid = 8045 & revision = 0.0.1 & side = provider&timestamp = 1491546674441 & version = 0.0.1

\

-> ServiceConfig exportLocal()

-> Exporter<? > exporter = protocol.export(proxyFactory.getInvoker(ref, (Class) interfaceClass, local));

# Expose the Invoker<XxxService> invocation service proxy class

\

-> proxyFactory.getInvoker(ref, (Class) interfaceClass, local)

AbstractProxyInvoker >

public abstract class AbstractProxyInvoker<T> implements Invoker<T> {

private final T proxy; // The agent target instance XxxServiceImpl

private final Class<T> type;

private final URL url;

}

-> InvokerInvocationHandler.invoke()

#invoker.invoke(new RpcInvocation(method, args)).recreate();

\

-> DubboProtocol export(Invoker<T> invoker)

# return expose my friend <T>

public class DubboExporter<T> extends AbstractExporter<T> {

private final String key; / / com. Unj. Dubbotest. Provider. DemoService: 0.0.1:20880

private final Map<String, Exporter<? >> exporterMap;

public DubboExporter(Invoker<T> invoker, String key, Map<String, Exporter<? >> exporterMap){

super(invoker);

this.key = key;

this.exporterMap = exporterMap;

}

\

-> DubboProtocol openServer(url)

# url dubbo: / / 10.199.66.242:20880 / com. Unj. Dubbotest. Provider. DemoService? Anyhost = true&application = dubbo_demo & dubbo = 2.4.9 & interface = com. Unj. Dubbotest. Provider. DemoService&methods = sayHello, getUse Rs&pid = 8045 & revision = 0.0.1 & side = provider&timestamp = 1491546674441 & version = 0.0.

#serverMap.put(key, createServer(url)); Key: 10.199.66.242:20880 value: ExchangeServer

\

-> DubboProtocol createServer(URL url)

Return HeaderExchangeServer, add parameter list such as heartbeat, heartbeat time

-> Exchangers.bind(url, requestHandler);

# returns HeaderExchangeServer, getTransporter () to obtain an instance of the derived from the configuration, the default returns a NettyTransporter

-> HeaderExchangeServer.bind(URL url, ExchangeHandler handler);

-> HeaderExchangeServer(Transporters.bind(url, new DecodeHandler(new HeaderExchangeHandler(handler))));

#HeaderExchangeServer Wrap instance NettyServer

\

-> NettyTransporter.bind(URL url, ChannelHandler listener)

#return new NettyServer(url, listener)

\

-> NettyServer.doOpen();

Open the socket listening port to receive messages

#ServerBootstrap bind(getBindAddress()) bind the address port

#RpcInvocation invocation class name, method name, invocation parameter

#DubboInvoker – Perform a specific remote call, including initialization information such as client

#Protocol – Publishing and subscribing to service addresses

#Exporter – Reference to an exposure service, or cancel exposure

\

Two: consume

->ReferenceConfig.init

Consume starts initialization

->DubboProtocol.refer

# Build Invoker based on parameters url, interface, etc

->JavassistProxyFactory.getProxy(Invoker<T> invoker, Class<? >[] interfaces)

GetProxy (interfaces).newinstance (new InvokerInvocationHandler(invoker));

->DemoService.say(String hello); # when actually called

->InvokerInvocationHandler.invoke(Object proxy, Method method, Object[] args)

#invoker.invoke(new RpcInvocation(method, args)).recreate(); RpcInvocation Packaging parameter method name

->DubboInvoker.doInovke(final Invocation invocation)

# unified proxy invocation

– > ExchangeClient. Send (invocation, isSent);

->HeaderExchangeChannel.request(Object request, int timeout)

->NettyChannel.send(Object message, boolean sent)

\

Three: dubbo communication: NettyClient <– asynchronous NIO transmission socket listening -> NettyServer

Consume –> Provider call process:

– > NettyServer – > NettyHandler. MessageReceived # receives the message handler

-> MultiMessageHandler->HeartbeatHandler->AllChannelHandler->DecodeHandler->HeaderExchangeHandler->DubboProtocol$requestHan dler

MultiMessageHandler is bundled when NettyServer is started

# dubboProtocol.getServers () retrieve serverMap to get my Exporter<? >

# dubboprotocol.getservers () retrieves serverMap for ExchangeServer

-> ExchangeHandlerAdapter.reply

# Really get the Invoker, will pass the Message conversion Invocation

-> invoker.invoke(invocation)

-> JavassistProxyFactory$AbstractProxyInvoker.doInvoke

AbstractProxyInvoker calls the target reference service, the client DubboInvoker

\