This article is a series of articles on RPC framework Dubbo from Understanding to Using.
This article explains the Dubbo supported registry, Dubbo load balancing policies, and the installation of the Dubbo console.
Registry Support
The registry can manage system services more efficiently, such as publishing service interfaces, automatically removing invalid services, and automatically restoring services.
Dubbo supports five registries: Multicast, Nacos(recommended), ZooKeeper(recommended), Redis, and Simple. This article focuses on the first three, and more information about registries can be found at: dubbo.apache.org/zh-cn/docs/…
Multicast registry
Multicast registries do not need to start any central node, as long as the broadcast address is the same, they can discover each other.
- The provider broadcasts its own address at startup
- The consumer broadcasts the subscription request when it starts
- When the provider receives a subscription request, unicast its own address to the subscriber, if set
unicast=false
, broadcast to subscribers - When the consumer receives the provider’s address, it connects to the address for an RPC call.
Multicast is limited by the network structure and is only suitable for small-scale applications or development. Multicast address range: 224.0.0.0 to 239.255.255.255
configuration
<dubbo:registry address=Multicast: / / 224.5.6.7: "1234" />
Copy the code
or
<dubbo:registry protocol="multicast" address="224.5.6.7:1234" />
Copy the code
or
dubbo.register.address=Multicast: / / 224.5.6.7:1234
Copy the code
To reduce the amount of broadcasts, Dubbo default uses unicast provider address information to the consumer. If multiple consumer processes are started on a machine at the same time, the consumer needs to declare unicast=false, otherwise only one consumer will receive the message.
When the server and the consumer run on the same machine, the consumer also needs to declare unicast=false. Otherwise, the consumer cannot receive messages and No Provider available for the Service is abnormal.
<dubbo:registry address="Multicast: / / 224.5.6.7:1234? unicast=false" />
Copy the code
or
<dubbo:registry protocol="multicast" address="224.5.6.7:1234">
<dubbo:parameter key="unicast" value="false" />
</dubbo:registry>
Copy the code
The ZooKeeper registry
Apache ZooKeeper is an open source distributed application coordination component, which is an important component of Hadoop and Hbase. It provides consistency services for distributed applications, including configuration and maintenance, domain name service, distributed synchronization, and group service. Suitable as a registry for Dubbo services, high industrial strength, can be used in a production environment, recommended.
ZooKeeper’s main role in the development of micro-service projects is to serve as a service registry. We can register the prepared services with ZooKeeper.
Process description:
- Service provider startup: to
/dubbo/com.foo.BarService/providers
Write your OWN URL address in the directory. - Service consumer startup: Subscribe
/dubbo/com.foo.BarService/providers
The provider URL in the directory. And to the/dubbo/com.foo.BarService/consumers
Write your OWN URL address in the directory. - Monitor center startup: Subscribe
/dubbo/com.foo.BarService
All provider and consumer urls under the directory.
Supports the following functions:
- The registry can automatically delete provider information when the provider has an abnormal outage such as power outage;
- When the registry is restarted, the registration data and subscription requests can be automatically restored.
- When the session expires, the registration data and subscription requests can be automatically restored.
- When setting
<dubbo:registry check="false" />
Failed registration and subscription requests are recorded, and the background periodically tries again. - through
<dubbo:registry username="admin" password="1234" />
Set zooKeeper login information. - through
<dubbo:registry group="dubbo" />
If the root node of ZooKeeper is not configured, the default root node is used. - support
*
The wildcard<dubbo:reference group="*" version="*" />
Providers for all groupings and versions of subscribeable services.
Preparatory work
Before you integrate ZooKeeper into your Dubbo project, make sure the ZooKeeper service is started in the background.
Quick learning
The steps for Dubbo to merge ZooKeeper into a registry are simple. The steps can be divided into “Adding Maven dependencies” and “Configuring the registry”.
Rely on
Add zooKeeper jar dependencies to provider and Consumer:
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.6.1 track</version>
</dependency>
Copy the code
Dubbo supports two Zookeeper client implementations: zkClient and Curator:
Note: the zkClient implementation has been removed from 2.7.x, and you will need to extend it if you want to use the ZkClient client.
Therefore, we also need to add the Co-curator jar package dependency to the provider and consumer:
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>5.1.0</version>
</dependency>
Copy the code
Note: Adding zooKeeper and curator dependencies separately requires attention to whether there are conflicts between versions, which can be troublesome.
So, the once-and-for-all solution is to add an associated dependency given by Apache Dubbo:
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.4.1</version>
<type>pom</type>
</dependency>
Copy the code
configuration
ZooKeeper single-node configuration:
<dubbo:registry address=Zookeeper: / / 191.168.10.101: "2181" />
Copy the code
Or:
<dubbo:registry protocol="zookeeper" address="191.168.10.101:2181" />
Copy the code
Or:
dubbo.register.address=Zookeeper: / / 192.168.10.101:2181
Copy the code
Or:
dubbo.register.protocol=zookeeper
dubbo.register.address=192.168.10.101:2181
Copy the code
ZooKeeper cluster configuration:
<dubbo:registry address=Zookeeper: / / 191.168.10.101:2181? Backup = 191.168.10.102:2181191168 10.103:2181" />
Copy the code
Or:
<dubbo:registry protocol="zookeeper" address="191.168.10.101:2181191168 10.102:2181191168 10.103:2181" />
Copy the code
Or:
dubbo.register.address=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
Copy the code
Or:
dubbo.register.protocol=zookeeper
dubbo.register.address=192.168.10.101:2181192168 10.102:2181192168 10.103:2181
Copy the code
Nacos Registry
Nacos is an open source tool launched by Alibaba for service discovery and configuration management of distributed systems. Nacos is an important registry implementation in the Dubbo ecosystem, in which Dubo-Registrie-Nacos is the implementation of Dubbo fusion Nacos registry, which is recommended.
Nacos official website: nacos. IO /zh-cn/
Github:github.com/alibaba/nac…
Preparatory work
Before you integrate Nacos into your Dubbo project, make sure the Nacos service is started in the background.
Quick learning
The steps for Dubbo to merge Nacos into a registry are simple and can be divided into “Adding Maven dependencies” and “configuring the registry.”
Rely on
The core dependencies are dubbo-Registry -nacos and nacos-client.
<! -- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-registry-nacos -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>2.7.4.1</version>
</dependency>
<! -- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.3.1</version>
</dependency>
Copy the code
Configuring the Registry
The service provider and service consumer need only adjust the Address property configuration.
Single-machine configuration:
<! -- Using the Nacos registry, standalone -->
<dubbo:registry address="Nacos: / / 127.0.0.1:8848"/>
<! - or - >
<dubbo:registry protocol="nacos" address="127.0.0.1:2181"/>
Copy the code
Or:
dubbo.register.address=Nacos: / / 192.168.10.101:8848
Copy the code
Or:
dubbo.register.protocol=nacos
dubbo.register.address=192.168.10.101:8848
Copy the code
Cluster configuration:
<! -- Using the Nacos registry, Cluster Edition -->
<dubbo:registry address="Nacos: / / 192.168.10.101:8848? Backup = 192.168.10.102:8848192168 10.103:8848"/>
<! - or - >
<dubbo:registry protocol="nacos" address="192.168.10.101:8848192168 10.102:8848192168 10.103:8848"/>
Copy the code
Or:
dubbo.register.address=Nacos: / / 192.168.10.101:8848
Copy the code
Or:
dubbo.register.protocol=nacos
dubbo.register.address=192.168.10.101:8848192168 10.102:8848192168 10.103:8848
Copy the code
Then, restart your Dubbo application and Dubbo’s service offering and consumption information will be displayed in the Nacos console.
As shown in the figure, information with service names prefixed with providers: is the meta information of service providers, while consumers: is the meta information of service consumers. Click “Details” to view service status details:
Dubbo load balancing
For cluster load balancing, Dubbo provides multiple load balancing policies. The default value is Random. You can also expand the load balancing policies.
Load Balancing Policy
Random LoadBalance
- Random, set random probability according to weight.
- The probability of collision on a section is high, but the distribution is more uniform with the increase of adjustment dosage, and the distribution is more uniform after using weight according to the probability, which is conducive to dynamic adjustment of provider weight.
RoundRobin LoadBalance
- Polling, the polling ratio is set according to the weight after the convention.
- There is the problem of slow providers accumulating requests, for example: the second machine is slow but not hung up, gets stuck when the request is switched to the second machine, and over time all the requests get stuck to the second machine.
LeastActive LoadBalance
- Minimum number of active calls, ping value (low latency) calls, same latency case random.
- Make slower providers receive fewer requests, because slower providers have a larger difference in the count before and after the invocation.
ConsistentHash LoadBalance
- Consistent Hash, where requests with the same parameters are always sent to the same provider.
- When a provider hangs, requests originally sent to that provider are spread over other providers based on virtual nodes without drastic changes.
- Algorithm is used to refer to: en.wikipedia.org/wiki/Consis…
- By default, only the first parameter Hash is used. If you want to change it, configure it
"Dubbo: parameter key =" hash. The arguments "value =" 0, 1 "/ >
- By default, 160 virtual nodes are used. If you want to change the number, configure the number
<dubbo:parameter key="hash.nodes" value="320" />
configuration
Weights are not assigned at the code level in projects, but are assigned to service dynamics by the monitoring center (dubbo-admin), official documentation: dubbo.apache.org/zh-cn/docs/…
xml
Service level of the server
<dubbo:service interface="..." loadbalance="roundrobin" weight="100" />
Copy the code
Client service level
<dubbo:reference interface="..." loadbalance="roundrobin" />
Copy the code
Server method level
<dubbo:service interface="..." weight="100">
<dubbo:method name="..." loadbalance="roundrobin"/>
</dubbo:service>
Copy the code
Client method level
<dubbo:reference interface="...">
<dubbo:method name="..." loadbalance="roundrobin"/>
</dubbo:reference>
Copy the code
yaml
dubbo:
provider:
loadbalance: roundrobin
weight: 100
consumer:
loadbalance: roundrobin
Copy the code
annotations
@Service(loadbalance = "roundrobin", weight = 100)
@Reference(loadbalance = "roundrobin")
Copy the code
Dubbo console
In Dubbo 2.6 and before, we used a WAR package, which was deployed under Tomcat. Just start the server to access the WAR package project, and the interface effect is as follows.
After version 2.7 of Dubbo, the management console adopts the way of separating the front and back ends. Vue and Vuetify are used as Javascript framework and UI framework respectively in the front end, and Spring Boot framework is used in the back end. It can be packaged and deployed in accordance with the standard Maven mode, and can also be deployed in the front and back end separation mode, which is convenient for development. In terms of functions, there are currently three parts of service query, service governance (including the new governance rules in Dubbo2.7) and service test, and the final results are as follows:
The deployment of
Maven Deployment
Methods a
Clone the project locally using Git, package the startup access, or import the IDE startup access
git clone https://github.com/apache/dubbo-admin.git
cd dubbo-admin
mvn clean package -Dmaven.test.skip=true
cdDubbo - admin - distribution/target Java jar dubbo - admin - 0.2.0 - the SNAPSHOT. The jarCopy the code
The project can be accessed at http://localhost:8080
Way 2
Access: github.com/apache/dubb… Download the project locally, package startup access, or import IDE startup access.
The front and rear ends are deployed separately
The front end
cd dubbo-admin-ui
npm install
npm run dev
Copy the code
The back-end
cd dubbo-admin-server
mvn clean package -Dmaven.test.skip=true
cdTarget Java jar dubbo - admin server - 0.2.0 - the SNAPSHOT. The jarCopy the code
- run
dubbo admin server
dubbo admin server
Is a standard Spring Boot project that can be run in any Java IDE - run
dubbo admin ui
dubbo admin ui
Managed and built by NPM, in a development environment, can run separately:npm run dev
- Page access: Visit http://localhost:8082. Because the front and back ends are deployed separately and the front end supports hot loading, any page modification can be reported in real time without restarting the application.
- Cross-domain problem: To facilitate development, the project uses the deployment mode of separating the front and back ends. The main advantage is that the front end supports hot deployment. In this mode, the front end accesses the restful API interface of the back end through port 8080 to obtain data, which causes cross-domain access problems. So we are working on
dubbo-admin-ui/config/index.js
Added the configuration to support cross-domain accessnpm run dev
When started separately, these configurations are activated, allowing cross-domain access.
Core configuration file
dubbo-admin-server/src/main/resources/application.properties
Copy the code
The main configurations are as follows (to modify the configuration, replace it with your own ZooKeeper server address) :
# centers in dubbo2.7
admin.registry.address=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
admin.config-center=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
admin.metadata-report.address=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
admin.root.user.name=root
admin.root.user.password=root
Copy the code
The three configuration items specify the addresses of the registry, configuration center, and metadata center respectively.
Swagger support
Deployment is completed, you can visit: http://localhost:8080/swagger-ui.html to view all the RESTful API.
access
In this paper, front-end and back-end separation is used for deployment. Visit: http://localhost:8082/, and the results are as follows:
You need to enter the user name and password root for the first access.
After a successful login, the main window is as follows. You can query, manage, test, Mock, and collect statistics on the left menu.
Click the details button on the right of the query result to enter the following page to view basic information, service information and metadata information. If the metadata information cannot be obtained, modify the configuration.
Dubo-admin configuration instructions have been provided. Follow the instructions to configure dubo-admin.
Resolve the problem that metadata cannot be obtained
Use ZooKeeper graphical client tool ZooInspector to connect to ZooKeeper to modify Dubbo configuration information.
In the dubbo directory, add nodes config → dubbo and dubbo.properties. On the right, enter the configuration information.
admin.registry.address=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
admin.metadata-report.address=Zookeeper: / / 192.168.10.101:2181? Backup = 192.168.10.102:2181192168 10.103:2181
Copy the code
After the above operations are complete, repackage and compile to start, and view the details again to see the metadata information.
That concludes the Dubbo framework.
This article is licensed under a Creative Commons attribution – Noncommercial – No Deductive 4.0 International license.
You can check out more articles about Dubbo in the category below.
🤗 your likes and retweets are the biggest support for me.
📢 Scan code pay attention to Mr. Hallward “document + video” each article is equipped with a special video explanation, learning more easily oh ~