Dubbo and Zookeeper integration

Dubbo and Zookeeper integration

Distributed theory:

In the book "Principles and Paradigms of Distributed Systems", it is defined as follows: "A distributed system is a collection of several independent computers that appear to users as a single related system";

A distributed system is a system composed of a group of computer nodes that communicate over a network and coordinate their work to accomplish a common task. The emergence of distributed systems is to use cheap and ordinary machines to complete computing and storage tasks that a single computer cannot. The purpose is to use more machines to process more data .

A distributed system is a software system built on a network.

The first thing to be clear is that only when the processing power of a single node cannot meet the increasing computing and storage tasks, and the hardware upgrade (adding memory, adding disk, using a better CPU) is so high that it is not worth the loss, the application When we cannot optimize further, we need to consider distributed systems. Because the problem to be solved by the distributed system itself is the same as that of the stand-alone system, and due to the topology structure of the distributed system with multiple nodes and communication through the network, it will introduce many problems that the stand-alone system does not have. In order to solve these problems, it will introduce more mechanism and protocol, bring more problems. . .

Dubbo

With the development of the Internet, the scale of website applications continues to expand, and the conventional vertical application architecture can no longer cope. Distributed service architecture and mobile computing architecture are imperative, and a governance system is urgently needed to ensure the orderly evolution of the architecture.

insert image description here
1. Single Application Architecture (ORM)

When the website traffic is very small, only one application is needed, and all functions such as order payment and so on are deployed together to reduce deployment nodes and costs. Disadvantages: A single system architecture makes more and more resources occupied in the development process, and becomes more and more difficult to maintain as traffic increases

Disadvantages :

1. Performance expansion is difficult

2. Collaborative development issues

3. Not conducive to upgrade and maintenance

2. Vertical Application Framework (MVC)

The vertical application architecture solves the capacity expansion problem faced by a single application architecture. The traffic can be dispersed among various subsystems, and the volume of the system is controllable, which reduces the cost of collaboration and maintenance among developers to a certain extent, and improves the development efficiency.
Disadvantages : But in the vertical architecture, the same logic code needs to be copied continuously and cannot be reused.

3. Distributed application architecture (RPC)
When there are more and more vertical applications, the interaction between applications is inevitable. The core business is extracted as an independent service, and a stable service center is gradually formed.

4.
With the further development of service-oriented architecture (SOA), there are more and more services, and the invocation and dependencies between services are becoming more and more complex. The service-oriented architecture system (SOA) was born, and thus derived A series of corresponding technologies have been developed, such as service frameworks that encapsulate behaviors such as service provision, service invocation, connection processing, communication protocols, serialization methods, service discovery, service routing, and log output.

Test environment setup

Apache Dubbo |ˈdʌbəʊ| is a high-performance, lightweight open-source Java RPC framework that provides three core capabilities: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic service registration and discovery.

Dubbo basic concepts (core)

insert image description here

Service Provider (Provider): The service provider that exposes the service. When the service provider starts, it registers the service it provides with the registry.

Service consumer (Consumer): The service consumer that invokes the remote service. When the service consumer starts, it subscribes to the registration center for the service it needs. The service consumer selects from the provider address list based on the soft load balancing algorithm. One provider makes the call, and if the call fails, another call is chosen.

Registry : The registry returns the service provider address list to the consumer. If there is a change, the registry will push the change data to the consumer based on the long connection

Monitoring Center (Monitor): Service consumers and providers, accumulate the number of calls and call time in memory, and regularly send statistical data to the monitoring center every minute

Description of calling relationship

l The service container is responsible for starting, loading, and running the service provider.

l When the service provider starts up, it registers the services it provides with the registry.

l When the service consumer starts, it subscribes to the registration center for the services it needs.

l The registry returns the service provider address list to the consumer. If there is a change, the registry will push the change data to the consumer based on the persistent connection.

l Service consumers, from the provider address list, select one provider to call based on the soft load balancing algorithm. If the call fails, select another provider to call.

l Service consumers and providers accumulate the number of calls and call times in memory, and regularly send statistical data to the monitoring center every minute.

Dubbo environment construction

  1. Here, zookeeper is used as the registration center, the version is selected as 3.5.7, and zookeeper is decompressed

    zookeeper, a distributed service framework, is a sub-project of Apache Hadoop. It is mainly used to solve some data management problems often encountered in distributed applications, such as: unified naming service, state synchronization service, cluster management, Management of distributed application configuration items, etc.

  2. Run /bin/zkServer.cmd, please set the zoo.cfg configuration file before running; if you encounter a crash, edit the zkServer.cmd file and add pause at the end. In this way, the operation will not exit when an error occurs, and an error message will be prompted to facilitate finding the cause.

  3. Modify the zoo.cfg configuration file

    Copy the zoo_sample.cfg under the conf folder and rename it to zoo.cfg.

    Note a few important locations:

    dataDir=./ directory for temporary data storage (writable relative path)

    clientPort=2181 port number of zookeeper

    After the modification is completed, start zookeeper again
    insert image description here

  4. Test with zkCli.cmd

insert image description here

  1. Create a node and get the specified node
    insert image description here

  2. Download and install dubbo-admin

dubbo itself is not a service software. It is actually a jar package that can help your java program connect to zookeeper, and use zookeeper to consume and provide services.

However, in order to allow users to better manage and monitor many dubbo services, the official provides a visual monitoring program dubbo-admin, but this monitoring does not affect the use even if it is not installed.

1. Download dubbo-admin

Address: https://github.com/apache/dubbo-admin/tree/master

2. Unzip into the directory

Modify dubbo-admin\src\main\resources \application.properties to specify the zookeeper address

server.port=7001
spring.velocity.cache=false
spring.velocity.charset=UTF-8
spring.velocity.layout-url=/templates/default.vm
spring.messages.fallback-to-system-locale=false
spring.messages.basename=i18n/message
spring.root.password=root
spring.guest.password=guest

dubbo.registry.address=zookeeper://127.0.0.1:2181

3. Use cmd to package dubbo-admin in the project directory

mvn clean package -Dmaven.test.skip=true

insert image description here

4. Execute the jar package after packaging

java -jar dubbo-admin-0.0.1-SNAPSHOT.jar

[Note: The zookeeper service must be turned on!

After the execution is completed, let's visit http://localhost:7001/, at this time we need to enter the login account and password, we are all the default root-root;
insert image description here

Guess you like

Origin blog.csdn.net/qq_38338409/article/details/118371445