Reference address ：https://www.cnblogs.com/alisystemsoftware/p/13064620.html
Registry data structure format changes （service： Interface services ,application： A collection of application instances ,instance： Single application instance ）, What it brings is “ Service introspection ”
With Dubbo Take the current address discovery data format as an example , It is “RPC Service granularity ” Of , It is a RPC Service as key, Take the instance list as value To organize data ：
And what we've introduced is “ Application granularity service discovery ”, It takes the name of the app （Application） As key, A set of instances deployed with this application （Instance） List as value. This makes two differences ：
The data mapping relationship has changed , from RPC Service -> Instance Turn into Application -> Instance;
There's less data , The registry is gone RPC Service And related configuration information .
The above changes are called The basic mechanism of application level service discovery , Then explain why it's called “ Service introspection ”？
In fact, it still has to start from its working principle , We mentioned above , There are several significant changes in the data model that apply granular service discovery ： There's less data in the data center ,RPC Service related data is missing from the registry , Now only application - instance These two levels of data . To ensure that this part is missing RPC Service data can still be Consumer Right perception , We are Consumer and Provider A separate communication channel has been established ：Consumer and Provider Two pairs exchange information through specific ports , We put this Provider The act of exposing one's own information on one's own initiative is regarded as a mechanism of introspection , So from this point of view , We name the whole mechanism ： Service introspection .
Such a change given Dubbo Discover the benefits or reasons for converging to application level services , But at the same time, the service governance capability of interface granularity should be retained , This is a Dubbo Framework programming model ease of use 、 The foundation of service governance capability advantage .
Here is a complete workflow chart of service self reflection , Service registration is described in detail 、 Service discovery 、MetadataService、RPC The collaborative process between calls .
Service provider starts , First of all, analyze the application defined “ General service ” And registered as RPC service , And then the built-in MetadataService service , Finally open TCP Listening port ;
After startup , Register instance information to registry （ Limited to ip、port And so on ）, Provider startup complete ;
Service consumers start , First According to its need “ The consumption of provider Application name ” Check the address list at the registry , And complete the subscription （ To achieve automatic notification of subsequent address changes ）;
After the consumer gets the address list , Then right MetadataService A call , The returned result contains all application defined “ General service ” And related configuration information ;
thus , Consumers can receive external traffic , And launch... To the provider Dubbo RPC call .
Metadata synchronization mechanism
Client And Server After receiving the address push, the configuration synchronization is the key link of service introspection , At present, there are two specific options for metadata synchronization , Namely ： The built-in MetadataService; Independent metadata Center , Coordinate data through metadata clusters refined in .
The built-in MetadataService：MetadataService standard-passing Dubbo Protocol exposure , According to the query conditions , Will be in memory to meet the conditions of “ General service ” Configuration back to consumer . This step takes place before the consumer site selection and call ;
Metadata Center ： Reuse 2.7 Metadata center introduced in version ,provider After the instance is started , Will try to put the internal RPC Services are organized into metadata formats to metadata centers , and consumer After receiving the update from the registry , Active query metadata Center .
Be careful consumer When to query the metadata center at the end of the day , Wait until the registration center's address update notice . That is, the data sent through the registry , We can clearly know when the metadata of an instance is updated , At this point, you need to check the metadata center .
Changes brought about by reference service configuration ：