Registry Center Extension

Registry Center Extension

Extension Description

Responsible for the registration and discovery of services.

Extension Interfaces

  • org.apache.dubbo.registry.RegistryFactory
  • org.apache.dubbo.registry.Registry

Extension Configuration

  1. <!-- Define the registry -->
  2. <dubbo:registry id="xxx1" address="xxx://ip:port" />
  3. <!-- Reference the registry, if the registry attribute is not configured, it will automatically scan the registry configuration in the ApplicationContext -->
  4. <dubbo:service registry="xxx1" />
  5. <!-- Reference the default value of the registry, when <dubbo:service> does not configure the registry attribute, use this configuration -->
  6. <dubbo:provider registry="xxx1" />

Extension Contracts

RegistryFactory.java:

  1. public interface RegistryFactory {
  2. /**
  3. * Connect to the registry.
  4. *
  5. * The connection to the registry must handle the following contracts:<br>
  6. * 1. Setting check=false indicates no connection check, otherwise an exception will be thrown if it cannot connect.<br>
  7. * 2. Supports username:password authentication based on the URL.<br>
  8. * 3. Supports backup=10.20.153.10 alternative registry cluster addresses.<br>
  9. * 4. Supports file=registry.cache local disk file caching.<br>
  10. * 5. Supports timeout=1000 request timeout settings.<br>
  11. * 6. Supports session=60000 session timeout or expiration settings.<br>
  12. *
  13. * @param url The registry address, must not be null
  14. * @return The registry reference, never returns null
  15. */
  16. Registry getRegistry(URL url);
  17. }

RegistryService.java:

  1. public interface RegistryService { // Registry extends RegistryService
  2. /**
  3. * Register a service.
  4. *
  5. * Registration must handle the following contracts:<br>
  6. * 1. If the URL sets check=false, no error will be reported on registration failure, and it will retry in the background; otherwise, an exception will be thrown.<br>
  7. * 2. If the URL sets dynamic=false, it needs to be persisted; otherwise, it should be automatically deleted when the registrant exits abnormally due to power failure or other circumstances.<br>
  8. * 3. If the URL sets category=overrides, it indicates classified storage, with the default category being providers, allowing notifications of partial data by category.<br>
  9. * 4. Data must not be lost when the registry restarts or during network fluctuations, including automatic deletion of data upon disconnection.<br>
  10. * 5. URLs with the same URI but different parameters are allowed to coexist and cannot be overwritten.<br>
  11. *
  12. * @param url The registration information, must not be null, such as: dubbo://10.20.153.10/com.alibaba.foo.BarService?version=1.0.0&application=kylin
  13. */
  14. void register(URL url);
  15. /**
  16. * Unregister a service.
  17. *
  18. * Unregistration must handle the following contracts:<br>
  19. * 1. If it is dynamic=false persistent storage data and the registration data cannot be found, throw IllegalStateException, otherwise ignore.<br>
  20. * 2. Unregister based on full URL match.<br>
  21. *
  22. * @param url The registration information, must not be null, such as: dubbo://10.20.153.10/com.alibaba.foo.BarService?version=1.0.0&application=kylin
  23. */
  24. void unregister(URL url);
  25. /**
  26. * Subscribe to a service.
  27. *
  28. * Subscription must handle the following contracts:<br>
  29. * 1. If the URL sets check=false, no error will be reported on subscription failure, and it will retry in the background.<br>
  30. * 2. If the URL sets category=overrides, only notify the specified categorized data; multiple categories are separated by commas and wildcard '*' is allowed to subscribe to all categorized data.<br>
  31. * 3. Allows querying based on interface, group, version, classifier, such as: interface=com.alibaba.foo.BarService&version=1.0.0<br>
  32. * 4. The query criteria allow wildcards, subscribing to all groups of all versions of all interfaces, or: interface=*&group=*&version=*&classifier=*<br>
  33. * 5. When the registry restarts or during network fluctuations, subscription requests must be automatically restored.<br>
  34. * 6. URLs with the same URI but different parameters are allowed to coexist and cannot be overwritten.<br>
  35. * 7. The subscription process must be blocked, returning only after the first notification is completed.<br>
  36. *
  37. * @param url The subscription criteria, must not be null, such as: consumer://10.20.153.10/com.alibaba.foo.BarService?version=1.0.0&application=kylin
  38. * @param listener The change event listener, must not be null
  39. */
  40. void subscribe(URL url, NotifyListener listener);
  41. /**
  42. * Unsubscribe from a service.
  43. *
  44. * Unsubscription must handle the following contracts:<br>
  45. * 1. If there is no subscription, just ignore it.<br>
  46. * 2. Unsubscribe based on full URL match.<br>
  47. *
  48. * @param url The subscription criteria, must not be null, such as: consumer://10.20.153.10/com.alibaba.foo.BarService?version=1.0.0&application=kylin
  49. * @param listener The change event listener, must not be null
  50. */
  51. void unsubscribe(URL url, NotifyListener listener);
  52. /**
  53. * Query the registration list, corresponding to the push mode of subscription, here it is the pull mode, returning results only once.
  54. *
  55. * @see org.apache.dubbo.registry.NotifyListener#notify(List)
  56. * @param url The query criteria, must not be null, such as: consumer://10.20.153.10/com.alibaba.foo.BarService?version=1.0.0&application=kylin
  57. * @return The list of registered information, may be empty, meaning the same as the parameters of {@link org.apache.dubbo.registry.NotifyListener#notify(List<URL>)}.
  58. */
  59. List<URL> lookup(URL url);
  60. }

NotifyListener.java:

  1. public interface NotifyListener {
  2. /**
  3. * Triggered when a service change notification is received.
  4. *
  5. * The notification must handle the following contracts:<br>
  6. * 1. Always notify the full set of data dimensioned by service interface and data type, i.e., it will not notify partial data of the same type from a service, and the user does not need to compare the previous notification results.<br>
  7. * 2. The first notification during subscription must be a full notification of all types of data for a service.<br>
  8. * 3. During changes, different types of data may be notified separately, for example: providers, consumers, routes, overrides; only one type may be notified, but that type’s data must be complete, not incremental.<br>
  9. * 4. If any type of data is empty, an empty protocol notification with a category parameter must be sent.<br>
  10. * 5. The notifier (i.e., the registry implementation) must ensure the order of notifications; for instance: single-threaded pushes, queue serialization, version comparison.<br>
  11. *
  12. * @param urls The list of registered information, never null, meaning the same as the return value of {@link org.apache.dubbo.registry.RegistryService#lookup(URL)}.
  13. */
  14. void notify(List<URL> urls);
  15. }

Known Extensions

org.apache.dubbo.registry.support.dubbo.DubboRegistryFactory

Extension Example

Maven Project Structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxRegistryFactory.java (implementing RegistryFactory interface)
  7. |-XxxRegistry.java (implementing Registry interface)
  8. |-resources
  9. |-META-INF
  10. |-dubbo
  11. |-org.apache.dubbo.registry.RegistryFactory (plain text file, content: xxx=com.xxx.XxxRegistryFactory)

XxxRegistryFactory.java:

  1. package com.xxx;
  2. import org.apache.dubbo.registry.RegistryFactory;
  3. import org.apache.dubbo.registry.Registry;
  4. import org.apache.dubbo.common.URL;
  5. public class XxxRegistryFactory implements RegistryFactory {
  6. public Registry getRegistry(URL url) {
  7. return new XxxRegistry(url);
  8. }
  9. }

XxxRegistry.java:

  1. package com.xxx;
  2. import org.apache.dubbo.registry.Registry;
  3. import org.apache.dubbo.registry.NotifyListener;
  4. import org.apache.dubbo.common.URL;
  5. public class XxxRegistry implements Registry {
  6. public void register(URL url) {
  7. // ...
  8. }
  9. public void unregister(URL url) {
  10. // ...
  11. }
  12. public void subscribe(URL url, NotifyListener listener) {
  13. // ...
  14. }
  15. public void unsubscribe(URL url, NotifyListener listener) {
  16. // ...
  17. }
  18. }

META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory:

  1. xxx=com.xxx.XxxRegistryFactory

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)