Dubbo client:
Request the server based on the configuration file
Search server mode: direct search, registry search
Registry query: through the registry to find the server address and implementation interface in the registry,
1, through the registry to find providers address circumstances (for example: < dubbo: registry address = “zookeeper: / / 10.20.153.10:2181” / >), ReferenceConfig parsing out the format of the URL is: registry://registry-host/com.alibaba.dubbo.registry.RegistryService? refer=URL.encode(“consumer://consumer-host/com.foo.FooService? Version = “1.0.0). 2, Based on the extension point adaptive mechanism, through the URL Registry :// protocol header recognition, will call the RegistryProtocol refer() method, based on the conditions in the refer parameter, query the provider URL, such as: dubbo://service-host/com.foo.FooService? Version = 1.0.0.
3. Based on the extension point adaptive mechanism, the refer() method of DubboProtocol will be called to get the provider reference through the dubbo:// protocol header recognition of the provider URL. RegistryProtocol then returns multiple provider references masquerading as a single provider reference through the Cluster extension point.
Client consumption process:
1. Firstly, the init method of ReferenceConfig class calls the refer method of Protocol to generate the Invoker instance (as shown in red in the figure above), which is the key of service consumption.
2. Next, convert Invoker to the interface required by the client (e.g. HelloWorld). For each protocol such as RMI/Dubbo/Web Service, which calls the refer method to generate an Invoker instance:
Dubbo implementation of the Dubbo protocol Invoker turns to my friend in the Export method of the DubboProtocol class, which mainly opens the socket listening service and receives various requests from the client. The communication details are implemented by Dubbo himself.
RMI implementation of the RMI protocol Invoker switch to the EXPORT method of the RmiProtocol class, which implements THE RMI service through Spring or Dubbo or JDK. The communication details are implemented by the JDK underlying. That saves a lot of work.
What is invoker?
Illustrate this with code examples for service consumption and provider:
Service Consumer code:
public class DemoClientAction {
private DemoService demoService;
public void setDemoService(DemoService demoService) {
this.demoService = demoService;
}
public void start() {
String hello = demoService.sayHello(“world” + i);
}
}
The DemoService in the code above is the proxy of the service consumer in the figure above. The user code calls its corresponding Invoker (any of DubboInvoker, HessianRpcInvoker, InjvmInvoker, RmiInvoker, WebServiceInvoker) through this proxy. This Invoker implements a true remote service invocation.
Service provider code:
public class DemoServiceImpl implements DemoService {
public String sayHello(String name) throws RemoteException {
return “Hello ” + name;
}
}
The class above will be encapsulated as an Instance of AbstractProxyInvoker and a new instance will be generated. In this way, when the network communication layer receives a request, it will find the corresponding Exporter instance and invoke its AbstractProxyInvoker instance, thus actually invoking the service provider’s code. There are a few other Invoker classes in Dubbo, but the two above are the most important.