In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to realize the unified model of URL in Dubbo". In the daily operation, I believe that many people have doubts about how to realize the unified model of URL in Dubbo. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to realize the unified model of URL in Dubbo". Next, please follow the editor to study!
Define
When we don't talk about dubbo, most of us are familiar with the concept of URL. Uniform Resource Locator (RFC1738--Uniform Resource Locators (URL)) should be the most well-known RFC specification, and its definition is also very simple.
The resources available on the Internet can be represented as simple strings, and this document describes the syntax and semantics of such strings. These strings are called "uniform Resource Locator" (URL).
A standard URL format can contain at most the following parts
Protocol://username:password@host:port/path?key=value&key=value
Some typical URL
Http://www.facebook.com/friends?param1=value1¶m2=value2https://username:password@10.20.130.230:8080/list?version=1.0.0ftp://username:password@192.168.1.7:21/1/read.txt
Of course, there are some unconventional URL that are also classified as URL.
192.168.1.3:20880
Url protocol = null, url host = 192.168.1.3, port = 20880, url path = null
File:///home/user1/router.js?type=script
Url protocol = file, url host = null, url path = home/user1/router.js
File://home/user1/router.js?type=script
Url protocol = file, url host = home, url path = user1/router.js
File:///D:/1/router.js?type=script
Url protocol = file, url host = null, url path = D:/1/router.js
File:/D:/1/router.js?type=script
Ditto file:///D:/1/router.js?type=script
/ home/user1/router.js?type=script
Url protocol = null, url host = null, url path = home/user1/router.js
Home/user1/router.js?type=script
Url protocol = null, url host = home, url path = user1/router.js
URL in Dubbo
In dubbo, a similar URL is used to pass data between extension points. The specific parameters that make up this URL object are as follows:
Protocol: generally speaking, various protocols in dubbo, such as dubbo thrift http zk
Username/password: username / password
Host/port: host / port
Path: interface name
Parameters: parameter key-value pair
Public URL (String protocol, String username, String password, String host, int port, String path, Map parameters) {if ((username = = null | | username.length () = = 0) & & password! = null & & password.length () > 0) {throw new IllegalArgumentException ("Invalid url, password without username!");} this.protocol = protocol; this.username = username; this.password = password; this.host = host; this.port = (port < 0? 0: port) This.path = path; / / trim the beginning "/" while (path! = null & & path.startsWith ("/")) {path = path.substring (1);} if (parameters = = null) {parameters = new HashMap ();} else {parameters = new HashMap (parameters);} this.parameters = Collections.unmodifiableMap (parameters);}
It can be seen that dubbo believes that protocol,username,passwored,host,port,path is the main URL parameter, and other key values are in the village house, ah, parameters.
Some typical Dubbo URL
Dubbo://192.168.1.6:20880/moe.cnkirito.sample.HelloService?timeout=3000
Describe a service with a dubbo protocol
Zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=demo-consumer&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=1214&qos.port=33333×tamp=1545721981946
Describe a zookeeper registry
Consumer://30.5.120.217/org.apache.dubbo.demo.DemoService?application=demo-consumer&category=consumers&check=false&dubbo=2.0.2&interface=org.apache.dubbo.demo.DemoService&methods=sayHello&pid=1209&qos.port=33333&side=consumer×tamp=1545721827784
Describe a consumer
It can be said that an implementation in any field can be thought of as a class of URL,dubbo that uses URL to uniformly describe metadata and configuration information throughout the framework.
URL-related lifecycle resolution services
Based on the META-INF/spring.handlers configuration within dubbo.jar, Spring calls back DubboNamespaceHandler when it encounters the dubbo namespace.
All dubbo tags are parsed using DubboBeanDefinitionParser, and XML tags are parsed into Bean objects based on one-to-one attribute mapping.
When ServiceConfig.export () or ReferenceConfig.get () initializes, the Bean object is converted to URL format, and all Bean properties are converted to parameters of URL.
Then the URL is passed to the protocol extension point, and based on the extension point adaptive mechanism, the services of different protocols are exposed or referenced according to the protocol header of URL.
Exposure service
1. Only service ports are exposed:
In the absence of a registry and directly exposing the provider, the format of URL parsed by ServiceConfig is: dubbo://service-host/com.foo.FooService?version=1.0.0.
Based on the extension point adaptive mechanism, through the identification of the dubbo:// protocol header of URL, the export () method of DubboProtocol is directly called to open the service port.
two。 Expose the service to the registry:
When there is a registry and the provider address needs to be registered, the format of the URL parsed by ServiceConfig is: registry://registry-host/org.apache.dubbo.registry.RegistryService?export=URL.encode ("dubbo://service-host/com.foo.FooService?version=1.0.0")
Based on the extension point adaptation mechanism, through the registry:// protocol header identification of URL, the export () method of RegistryProtocol is called to register the provider URL in the export parameter with the registry first.
Then re-pass it to the Protocol extension point for exposure: dubbo://service-host/com.foo.FooService?version=1.0.0, and then based on the extension point adaptation mechanism, through the dubbo:// protocol header identification of the provider URL, the DubboProtocol's export () method is called to open the service port.
Reference service
1. Directly connected reference service:
In the absence of a registry and a directly connected provider, the format of the URL parsed by ReferenceConfig is: dubbo://service-host/com.foo.FooService?version=1.0.0.
Based on the extension point adaptive mechanism, through the identification of the dubbo:// protocol header of URL, the refer () method of DubboProtocol is directly called and the provider reference is returned.
two。 Discover reference services from the registry:
When there is a registry and the provider address is found through the registry, the format of the URL parsed by ReferenceConfig is: registry://registry-host/org.apache.dubbo.registry.RegistryService?refer=URL.encode ("consumer://consumer-host/com.foo.FooService?version=1.0.0").
Based on the extension point adaptation mechanism, through the identification of the registry:// protocol header of URL, the refer () method of RegistryProtocol is called to query the provider URL, such as dubbo://service-host/com.foo.FooService?version=1.0.0, based on the condition in the refer parameter.
Based on the extension point adaptation mechanism, through the dubbo:// protocol header identification of the provider URL, the refer () method of DubboProtocol is called and the provider reference is obtained.
RegistryProtocol then returns multiple provider references, disguised as a single provider reference, through the Cluster extension point.
The significance of URL Unified Model
For URL in dubbo, some people understand it as configuration bus, others understand it as unified configuration model, although the statement is different, but they all express the same meaning. such URL is regarded as a public contract in dubbo, all extension point parameters contain URL parameters, and URL is used as context information throughout the whole extension point design system.
Before URL, parameters could only be passed as strings, parsing and assembling constantly, resulting in the same type of interface, sometimes Map, and sometimes Parameters class wrapper:
Export (String url) createExporter (String host, int port, Parameters params)
Use the URL consistency model:
Export (URL url) createExporter (URL url)
In the latest dubbo code, we can see the heavy use of URL for the transmission of information between contexts, and the benefits are obvious:
1. So that code writers and readers can connect a series of parameters, and then form a specification, making the code easy to write and easy to read.
two。 Scalable, URL is equivalent to a set of parameters (equivalent to a Map), and its meaning is richer than that of a single parameter. When we extend the code, we can append the new parameters to the URL without changing the structure of the input parameters and return parameters.
3. The unified model, which is located in the org.apache.dubbo.common package, can be used as an expression of parameters by each extension module, which simplifies the concept and reduces the cost of code understanding.
At this point, the study on "how to implement the URL unified model in Dubbo" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.