Dubbo Multicast Registry is the relevant code implementation

Source: Internet
Author: User

Dubbo's Multicast Registration center has the following features:

    • Do not need to start any central node, as long as the broadcast address, you can find each other
    • Multicast is limited by the network structure and is only suitable for use in small-scale applications or development phases.
    • Multicast address segment: 224.0.0.0-239.255.255.255

For information on multicast, refer to the following article: http://www.cnblogs.com/ghj1976/p/5276452.html

The flow chart for the broadcast is as follows:

    1. The provider broadcasts its own address when it starts.
    2. The consumer broadcasts a subscription request at startup.
    3. When a provider receives a subscription request, it broadcasts its own address to the subscriber, and if Unicast=false is set, it is broadcast to the Subscriber.
    4. When the consumer receives the provider address, the address is connected to the RPC call.

We use Wireshark to monitor the process.

The filter condition at this time is: IP.DST=224.0.0.0/4 This IP address segment is the address segment of the broadcast, refer to: http://stackoverflow.com/questions/11400046/ Wireshark-filter-by-multicast-in-gui

The first packet sent, we can see is registered UDP packet, the core content is as follows:

Register dubbo://10.37.129.2:20880/com.alibaba.dubbo.demo.demoservice?anyhost=true&application= demo-provider&dubbo=2.5.4-snapshot&generic=false&interface=com.alibaba.dubbo.demo.demoservice& loadbalance=roundrobin&methods=sayhello&pid=3651&revision=2.5.4-snapshot&side=provider& timestamp=1459131958710

Then one subscribes to the UDP packet.

Subscribe provider://10.37.129.2:20880/com.alibaba.dubbo.demo.demoservice?anyhost=true&application= demo-provider&category=configurators&check=false&dubbo=2.5.4-snapshot&generic=false& interface=com.alibaba.dubbo.demo.demoservice&loadbalance=roundrobin&methods=sayhello&pid=3651& revision=2.5.4-snapshot&side=provider&timestamp=1459131958710

When the consumer starts, the following message is broadcast:

Register consumer://10.37.129.2/com.alibaba.dubbo.demo.demoservice?application=demo-consumer&category= consumers&check=false&dubbo=2.5.4-snapshot&interface=com.alibaba.dubbo.demo.demoservice& methods=sayhello&pid=3803&revision=2.5.4-snapshot&side=consumer&timestamp=1459134194229

Subscribe consumer://10.37.129.2/com.alibaba.dubbo.demo.demoservice?application=demo-consumer&category= providers,configurators,routers&dubbo=2.5.4-snapshot&interface=com.alibaba.dubbo.demo.demoservice& methods=sayhello&pid=3803&revision=2.5.4-snapshot&side=consumer&timestamp=1459134194229

In this way, both the producer and the consumer know each other, and then the specific call is made.

The specific call is a TCP packet that returns the following 2 contents

2.5.4-snapshot0 "Com.alibaba.dubbo.demo.demoservice0.0.0sayhelloljava/lang/string;world89hpath0" Com.alibaba.dubbo.demo.DemoService Interface0 "com.alibaba.dubbo.demo.demoserviceversion0.0.0z

08Hello world89, Response form provider:10.37.129.2:20880

This part of the registered code that we can github/alibaba/dubbo/dubbo-registry/dubbo-registry-multicast/src/main/java/com/alibaba/dubbo/in Registry/multicast/multicastregistry.java See here.

The entire registration-related interface is as follows, here is just extracting the Registerservice interface part of DUBBO-REGISTRY-API:

/**
* Registryservice. (SPI, Prototype, ThreadSafe)
*
* @see Com.alibaba.dubbo.registry.Registry
* @see Com.alibaba.dubbo.registry.registryfactory#getregistry (URL)
* @author WILLIAM.LIANGF
*/
Public interface Registryservice {

   /**
     * Registration data, such as: Provider address, consumer address, routing rules, overlay rules, and other data.
     *
     * Registration requires processing contract:<br>
     * 1. When the URL is set Check=false, the registration fails after the error, in the background timed retry, otherwise throw an exception. <br>
     * 2. When the URL is set dynamic=false parameter, it needs to be persisted, otherwise, when the registrant loses power and so on, it should be deleted automatically. <br>
     * 3. When the URL is set category=routers, the category store is represented, the default category is providers, and the data can be notified by the classification section. <br>
     * 4. When the registry restarts, the network jitter, cannot lose data, including disconnection automatically delete data. <br>
     * 5. Allow URLs with the same URI but different parameters to coexist, cannot overwrite. <br>
     *
     * @param URL registration information, not allowed to be empty, such as: dubbo://10.20.153.10 /com.alibaba.foo.barservice?version=1.0.0&application=kylin
     * *
     void register (URL url);

/**
* Cancel registration.
*
* Cancellation of registration is required to deal with contract:<br>
* 1. If it is dynamic=false persistent storage data, can not find the registration data, then throw illegalstateexception, otherwise ignored. <br>
* 2. Cancel registration by full URL match. <br>
*
* @param URL registration information, not allowed to empty, such as: Dubbo://10.20.153.10/com.alibaba.foo.barservice?version=1.0.0&application=kylin
*/
void unregister (URL url);

/**
* Subscribe to eligible registered data and push automatically when there is a change in registration data.
*
* Subscription processing contract:<br>
* 1. When the URL is set Check=false, the subscription fails without error, and retries in the background. <br>
* 2. When the URL is set to Category=routers, only the data for the specified category is notified, multiple classifications are separated by commas, and the asterisk is allowed to be used to indicate subscription to all categorical data. <br>
* 3. Allow Interface,group,version,classifier to be used as a conditional query, such as:interface=com.alibaba.foo.barservice&version=1.0.0<br>
* 4. And the query condition allows the asterisk to be wildcard, subscribing to all versions of all the groupings of all interfaces, or:interface=*&group=*&version=*&classifier=*<br>
* 5. When the registry restarts, network jitter requires automatic recovery of subscription requests. <br>
* 6. Allow URLs with the same URI but different parameters to coexist, not overwrite. <br>
* 7. The subscription process must be blocked, and then returned when the first notification is finished. <br>
*
* @param URL subscription conditions, not allowed to be empty, such as: Consumer://10.20.153.10/com.alibaba.foo.barservice?version=1.0.0&application=kylin
* @param listener Change event listener, not allowed to be empty
*/
void subscribe (URL url, Notifylistener listener);

/**
* Unsubscribe.
*
* Cancellation of subscription requires processing of contract:<br>
* 1. If there is no subscription, ignore it directly. <br>
* 2. Unsubscribe by full URL match. <br>
*
* @param URL subscription conditions, not allowed to be empty, such as: Consumer://10.20.153.10/com.alibaba.foo.barservice?version=1.0.0&application=kylin
* @param listener Change event listener, not allowed to be empty
*/
void unsubscribe (URL url, Notifylistener listener);

/**
* Query the eligible registered data, corresponding to the push mode of the subscription, here is the pull mode, return only once results.
*
* @see com.alibaba.dubbo.registry.notifylistener#notify (List)
* @param URL query conditions, not allowed to be empty, such as: Consumer://10.20.153.10/com.alibaba.foo.barservice?version=1.0.0&application=kylin
* @return Registered Information list, may be empty, meaning the same as {@link com.alibaba.dubbo.registry.notifylistener#notify (list<url>)} parameter.
*/
list<url> lookup (URL url);

}

Reference: http://dubbo.io/Multicast+Registry-zh.htm

Dubbo Multicast Registry is the relevant code implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.