Dubbo Version: 2.5.4
A Service release is a service delivery direction Registry registration service process so that the service consumer is consulted from the registry and invokes the service.
The service Publisher is configured in spring's configuration file as follows:
<bean id= "Demoservice" class= "Com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>
The above is a concrete implementation of the service configured in spring, which is a common bean in spring.
<dubbo:serviceinterface= "Com.alibaba.dubbo.demo.DemoService" ref= "Demoservice"/>
In the above configuration, the Spring container resolves the custom schema element Dubbo and translates it into the actual configuration implementation Servicebean, and exposes the service during startup.
In addition to inheriting Dubbo's own configuration abstract class (ServiceConfig), Servicebean implements a series of spring interfaces to participate in the launch of the spring container and the creation of the bean. Since spring instantiates the Servicebean as a singleton pattern, the singleton bean is pre-initialized in the last second step of the spring container ApplicationContext startup process. During the initialization of the bean, the beanname is set, the container ApplicationContext is set, and the afterpropertiesset of Initializingbean is recalled.
The last step Finishrefresh trigger the Contextrefreshedevent event, and Servicebean implements the Applicationlistener interface to listen for this event, The Servicebean, which was instantiated in the previous step, registers the event, so the Servicebean onapplicationevent (Applicationevent Event) method is triggered, In this method, the export method is triggered to expose the service.
Serviceconfig.doexporturls () Perform a specific export process
1. Loadregistries (True)
Checkregistry If there is no configuration registration in the XML, read the configuration from the dubbo.properties, build the Registryconfig object and assign a value
Building the registry URL Unified Data schema collection list<registryurl>
2. Because Dubbo supports multi-protocol configuration, traverse all protocols to export services to different registries according to different protocols
A) Determine if it is a generic exposure
b) Building a unified data model URL for exposing services based on protocols
c) Configure the Monitor to load monitor and set the URL to Monitor_key
d) Set the Export_key value to the previously built Exposure service URL for the registration Regitryurl
e) According to the specific implementation of the service, implementation interface and Regitryurl from the agent factory proxyfactory get Agent Invoker (inherited from Abstractproxyinvoker), it is a specific implementation of a proxy
f) Protocol.export (invoker) Exposure service Invoker
Invoker contains the registryurl that was passed in the previous step, and the protocol value of Registryurl is registry
Protocollistenerwrapper and Protocolfilterwrapper for the protocol for Registry_protocol to skip directly, ultimately by Registryprotocol processing the export process
Registryprotocol Exposure Service Process
The incoming invoker is registryurl from Proxyfactory invoker
1. Get the Providerurl from Invoker, and in the Get CacheKey, get the local cache Exporterchangeablewrapper (exporter proxy, based on CacheKey) Establishes the corresponding relationship of the returned exporter with the exporter of the Protocol export), if there is a return.
2. If not present, obtain providerurl based on incoming invoker, in Build Invokerdelegete (Origininvoker, Providerurl)
3. Protocol.exprot (Invokerdelegete), based on Providerurl's agreement (generally Dubbo Protocol), exposes the service through Protocol's set-up class and gets exporter
4. Exporter and Invoker build objects with Providerur exported Exporterchangeablewrapper cache to local
5. Obtained registryurl by Invoker.
Get registry from Registryfactory in accordance with Registryurl, get Registryurl's registry agreement, here we take the zookeeper protocol as an example. The extension mechanism obtained by Dubbo is Zookeeperregistryfactory, which gets the registrar for Zookeeperregistry
6. Get Providerurl from Invoker to get registryproviderurl in removal of fields that do not need to be seen in the registry
7. Registration Center (zookeeperregistry) Registration Registryproviderurl
Registry.register (Registryproviderurl)
8. Get Overridesubscribeurl from Registryproviderurl, in building Overridelistener
9. Registry.subscribe (Overridesubscribeurl, Overridesubscribelistener) Registry subscribe to this URL to be used when the data change notification is re-exposed, which zookeeper for example, The exposure service generates a node in the zookeeper and triggers a Overridesubscribelistener notify method to re-expose the service when the node changes
10. Build and return a new exporter instance
Dubboprotocol the process of exposing services
1. Get the unified Data Model URL from Invoker
2. Build Servicekey by URL (typically by port, interface name, version, group Group)
such as: com.alibaba.dubbo.demo.demoservice:20880 This is made up of interfaces and ports
3. Build Dubboexporter into local map cache
4. Based on URL openserver. Find the local cache with key url.getaddress if no ExchangeServer is created. Set heartbeat time, set encoding and decoding protocol
Bind server based on URL and Exchangehandler and return (specifically how to bind a presentation)
5. Return Dubboexporter Object
Official document Service Release sequence diagram
Publish activity diagram
Dubbo Source of four--dubbo Service release