In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure the registry in Dubbo". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to configure the registry for Dubbo".
Registry support
The registry can manage the services of the system more efficiently, such as the release of service interfaces, automatic elimination of invalid services, automatic recovery of services, and so on.
Dubbo supports five registries: Multicast, Nacos (recommended), ZooKeeper (recommended), Redis, and Simple.
Multicast registry
The Multicast registry does not need to start any central node, as long as the broadcast address is the same, it can discover each other.
The provider broadcasts its own address at startup
Broadcast subscription request when the consumer starts
When the provider receives the subscription request, it unicasts its own address to the subscriber, and if unicast=false is set, it broadcasts it to the subscriber.
When the consumer receives the provider's address, it connects to that address to make a RPC call.
Limited by the network structure, multicast is only suitable for small-scale applications or development phase. Multicast address range: 224.0.0.0-239.255.255.255
Configuration
Or
Or
Dubbo.register.address=multicast://224.5.6.7:1234
To reduce broadcast volume, Dubbo uses unicast by default to send provider address information to consumers. If multiple consumer processes are started on a machine at the same time, consumers need to declare unicast=false, otherwise only one consumer will receive the message.
When the server and the consumer are running on the same machine, the consumer also needs to declare unicast=false, otherwise the consumer will not be able to receive the message, resulting in an No provider available for the service exception.
Or
ZooKeeper registry
Apache ZooKeeper is an open source distributed application coordination component, which is an important component of Hadoop and Hbase. It is a software that provides consistency services for distributed applications, including configuration maintenance, domain name services, distributed synchronization, group services and so on. Suitable for Dubbo service registration center, high industrial intensity, can be used in production environment, recommended to use.
In the development of micro-service projects, the main role of ZooKeeper is to exist as a service registry, and we can register the written services with ZooKeeper.
Process description:
When the service provider starts: write its own URL address to the / dubbo/com.foo.BarService/providers directory.
When the service consumer starts: subscribe to the provider URL address under the / dubbo/com.foo.BarService/providers directory. And write your URL address to the / dubbo/com.foo.BarService/consumers directory.
When the monitoring center starts: subscribe to the URL addresses of all providers and consumers under the / dubbo/com.foo.BarService directory.
The following features are supported:
When the provider has an abnormal outage, such as a power outage, the registry can automatically delete the provider information.
When the registry restarts, it automatically recovers registration data and subscription requests
When the session expires, the registration data and subscription requests can be automatically restored.
When set, failed registration and subscription requests are recorded, and the background retries regularly.
You can set zookeeper login information
By setting the root node of the zookeeper, the default root node will be used if not configured.
The * wildcard is supported, and you can subscribe to all groups of services and providers of all versions.
Preparatory work
Before you integrate ZooKeeper into your Dubbo project, make sure that the ZooKeeper service has been started in the background.
Get started quickly
The procedure for Dubbo to merge ZooKeeper into a registry is very simple, and the general steps can be divided into "increasing Maven dependency" and "configuring registry".
Dependence
Add zookeeper client jar package dependencies to provider and consumer:
Org.apache.zookeeper zookeeper 3.6.1
Dubbo supports both zkclient and curator Zookeeper client implementations:
Note: the implementation of zkclient has been removed in version 2.7.x, and you need to expand it if you want to use the zkclient client.
Therefore, we also need to add curator client jar package dependencies to provider and consumer:
Org.apache.curator curator-framework 5.1.0
Note: it is troublesome to add zookeeper and curator dependencies separately to see if there are conflicts between versions.
So, the solution once and for all is to add an associated dependency given by Apache Dubbo:
Org.apache.dubbo dubbo-dependencies-zookeeper 2.7.4.1 pom configuration
ZooKeeper stand-alone configuration:
Or:
Or:
Dubbo.register.address=zookeeper://192.168.10.101:2181
Or:
Dubbo.register.protocol=zookeeperdubbo.register.address=192.168.10.101:2181
ZooKeeper cluster configuration:
Or:
Or:
Dubbo.register.address=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181
Or:
Dubbo.register.protocol=zookeeperdubbo.register.address=192.168.10.101:2181192.168.10.102:2181192.168.10.103:2181Nacos registry
Nacos is an open source tool developed by Alibaba, which is used to realize service discovery and configuration management in distributed systems. Nacos is an important registry implementation in Dubbo ecosystem, and dubbo-registry-nacos is the implementation of Dubbo integrated Nacos registry, which is recommended.
Nacos official website: https://nacos.io/zh-cn/
Github: https://github.com/alibaba/nacos
Preparatory work
Before you integrate Nacos into your Dubbo project, make sure that the Nacos service has been started in the background.
Get started quickly
The procedure for Dubbo to merge Nacos into a registry is very simple, and the general steps can be divided into "increasing Maven dependency" and "configuring registry".
Dependence
The core dependencies are mainly dubbo-registry-nacos and nacos-client.
Org.apache.dubbo dubbo-registry-nacos 2.7.4.1 com.alibaba.nacos nacos-client 1.3.1 configure the registry
Service providers and service consumers only need to adjust the address property configuration.
Stand-alone configuration:
Or:
Dubbo.register.address=nacos://192.168.10.101:8848
Or:
Dubbo.register.protocol=nacosdubbo.register.address=192.168.10.101:8848
Cluster configuration:
Or:
Dubbo.register.address=nacos://192.168.10.101:8848
Or:
Dubbo.register.protocol=nacosdubbo.register.address=192.168.10.101:8848192.168.10.102:8848192.168.10.103:8848
Then, restart your Dubbo application, and the service provision and consumption information of Dubbo can be displayed in the Nacos console.
As shown in the figure, the information prefixed with the service name providers: is the meta-information of the service provider, and consumers: represents the meta-information of the service consumer. Click "details" to view service status details:
Dubbo load balancing
In cluster load balancing, Dubbo provides a variety of balancing strategies, which are called randomly by random by default, or you can extend the load balancing strategy by yourself.
Load balancing Strategy Random LoadBalance
Random, set random probability by weight.
The probability of collision on a section is high, but the larger the amount of adjustment is, the more uniform the distribution is, and it is also more uniform after using the weight according to probability, which is beneficial to dynamically adjust the weight of the provider.
RoundRobin LoadBalance
Polling, setting the polling rate according to the weight after the convention.
There is a problem of slow provider accumulating requests, for example, the second machine is slow, but it doesn't hang up, it gets stuck when the request is transferred to the second machine, and over time, all requests are stuck on the second machine.
LeastActive LoadBalance
Minimum number of active calls, ping value (low latency) calls, random in the case of the same delay.
Causes slower providers to receive fewer requests, because the slower the provider, the greater the difference in count before and after invocation.
ConsistentHash LoadBalance
Consistent Hash, requests with the same parameters are always sent to the same provider.
When a provider hangs up, the request originally sent to that provider, based on the virtual node and spread equally to other providers, will not cause drastic changes.
For the algorithm, see: http://en.wikipedia.org/wiki/Consistent_hashing
By default, only the first parameter Hash. If you want to modify it, please configure the
160 virtual nodes are used by default. If you want to modify them, please configure
Configuration
Generally, the weight is not specified at the code level in the project, but the weight of the service dynamics is specified through the monitoring center (dubbo-admin). Official document: http://dubbo.apache.org/zh-cn/docs/admin/introduction.html
Xml
Server-side service level
Client service level
Server method level
Client method level
Yamldubbo: provider: loadbalance: roundrobin weight: 100consumer: loadbalance: roundrobin Note @ Service (loadbalance = "roundrobin", weight = 100) @ Reference (loadbalance = "roundrobin")
Dubbo console
Dubbo version 2.6 and previously we deployed it under tomcat through a war package, and then start the server to access the war package project. The interface effect is as follows.
After Dubbo 2.7, the front and back ends of the management console are separated. The front end uses Vue and Vuetify as the Javascript framework and UI framework respectively, and the back end uses the Spring Boot framework. It can be packaged and deployed according to the standard Maven method, or it can be deployed separately from the front and rear ends to facilitate development. Functionally, it has three parts: service query, service governance (including the new governance rules in Dubbo2.7) and service testing. The final results are as follows:
Deployment Maven deployment mode 1
Use git to clone the project locally, package to start access, or import IDE to start access
Git clone https://github.com/apache/dubbo-admin.gitcd dubbo-adminmvn clean package-Dmaven.test.skip=truecd dubbo-admin-distribution/targetjava-jar dubbo-admin-0.2.0-SNAPSHOT.jar
Project access address: http://localhost:8080
Mode two
Access: https://github.com/apache/dubbo-admin downloads the project locally, packages it to start access, or imports IDE to start access.
Front-end cd dubbo-admin-uinpm installnpm run dev back-end cd dubbo-admin-servermvn clean package-Dmaven.test.skip=truecd targetjava-jar dubbo-admin-server-0.2.0-SNAPSHOT.jar for separate deployment of front and rear end
Running dubbo admin server dubbo admin server is a standard Spring Boot project that can be run in any Java IDE
Running dubbo admin ui dubbo admin ui is managed and built by npm, and in the development environment, you can run it separately: npm run dev
Page access: visit http://localhost:8082. Because the front end is deployed separately and the front end supports hot loading, any page changes can be reported in real time without the need to restart the application.
Cross-domain problem: in order to facilitate development, the project uses the front-end separate deployment mode. The main advantage is that the front-end hot deployment is supported. In this mode, the front-end will access the back-end restful api interface through port 8080 to obtain data, which will lead to cross-domain access. Therefore, we have added configurations in dubbo-admin-ui/config/index.js that support cross-domain access. When the current side starts separately through npm run dev, these configurations will be activated to allow cross-domain access.
Core profile dubbo-admin-server/src/main/resources/application.properties
The main configurations are (if you need to modify it, replace it with the server address of your own ZooKeeper):
# centers in dubbo2.7admin.registry.address=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181admin.config-center=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181admin.metadata-report.address=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181admin.root.user.name=rootadmin.root.user.password=root
The three configuration items specify the addresses of the registry, configuration center, and metadata center, respectively.
Swagger support
After the deployment is complete, you can visit: http://localhost:8080/swagger-ui.html to view all RESTful API.
Visit
This article uses the front-end separation method to deploy. Visit: http://localhost:8082/. The results are as follows:
You need to enter a user name and password on the first visit, both of which are root.
After the login is successful, the main interface is as follows. You can query, manage, test, Mock, and count the service through the menu on the left.
Click the details button of the query result on the right in the above figure to go to the following page to view basic information, service information and metadata information. If the metadata information is not available as shown in the figure below, you need to continue to modify the configuration.
The official has given a complete description of the Dubbo-Admin configuration instructions, you can follow the instructions to configure.
Resolve the problem that metadata cannot be obtained
Use ZooKeeper graphical client tool ZooInspector connection ZooKeeper to modify Dubbo configuration information.
Add the node config → dubbo in the dubbo directory, then add dubbo.properties, and fill in the configuration information on the right.
Admin.registry.address=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181admin.metadata-report.address=zookeeper://192.168.10.101:2181?backup=192.168.10.102:2181192.168.10.103:2181
After completing the above operations, repackage the compilation to start, and check the details again to see the metadata information.
At this point, I believe you have a deeper understanding of "how to configure the registry for Dubbo". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.