Dubbo installation and use

A single application architecture

Insert picture description here
When a website has very little traffic, only one application is needed. But with the increase in traffic, maintenance costs will become larger.

Two vertical application architecture

Insert picture description here
The vertical structure splits the application into several unrelated small applications. Divide traffic into various subsystems. But the disadvantage is that the code with the same logic may have to be copied continuously in various systems.

Three distributed application architecture

Insert picture description here
Distributed application architecture (RPC Remote Procedure Call) is a communication method between processes. Allow remote services to be called as local services. The RPC framework is responsible for shielding the underlying transmission methods (such as TCP), serialization (such as XML/JSON) and communication details. The user only needs to know who provides what kind of remote service interface in what location.
RPC adopts a client/server model. The requestor is a client, and the service provider is a server. First, the client calling process sends a call message with process parameters to the service process, and then waits for the response message. On the server side, the process stays asleep until the call information arrives. When a call message arrives, the server obtains the process parameters, calculates the result, sends the reply message, and then waits for the next call message. Finally, the client calling process receives the reply message, obtains the process result, and then the call execution continues.

The RPC framework generally includes three parts:
a) service provider
b) service caller
c) registration center
We need to register the service, and then let the caller discover the service, which requires a registry to manage the addresses of all service providers . With the further development of servitization, there are more and more services, and the calls and dependencies between services are becoming more and more complex, giving birth to a service-oriented architecture (SOA). SOA is a coarse-grained, loosely coupled service-centric architecture.
The general principles of SOA service-oriented: services can be reused and loosely coupled (try not to rely on other independent service providers). The service is an abstraction of the underlying logic (only the exposed service is visible to the outside, and the underlying implementation is invisible). Services can be arranged in combination.

Introduction to Dubbo

Dubbo is an open source distributed service framework of Alibaba. Its biggest feature is that
it is structured in a layered manner, which can decouple the layers (or loosely coupling to the maximum). From the perspective of the service model, Dubbo uses a very simple model, either the provider provides services or the consumer consumes services, so based on this, the service provider and service consumer can be abstracted. (Consumer) Two roles.

Main roles in dubbo:

  • Provider producer, service provider
  • Consumer Consumer, the party calling the service
  • Registry registration service and discovery service place
  • Monitor monitoring center, statistics service call times and call time

How Dubbo works:

  • The lightweight Java container initializes the Spring context through the main function, publishes the service according to the specified protocol according to the XML file configured by the service provider, and completes the initialization of the service.
  • The service provider connects to the service registration center according to the configured service registration center address, and publishes the service provider information to the registration center.
  • The consumer connects to the registration center to obtain the specified service address according to the service reference information in the consumer's XML configuration file.
  • The service registry dynamically pushes service address information to designated consumers based on the service subscription relationship.
  • When a consumer calls a remote service, it selects a service provider from the locally cached service provider address list according to the routing strategy, and then resumes the link according to the protocol type to call the service provider across processes.

Dubbo call relationship:

  • The server is responsible for starting, loading, and running the provider (for example, in the tomcat container, starting the dubbo server).
  • Providers register their services with the registration center when they start.
  • When consumers start, they subscribe to the registry for the services they need.
  • The registry returns the 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.
  • Consumers, from the remote interface list, call the remote interface, dubbo will choose a provider to call based on the load balancing algorithm, and if the call fails, choose another one.
  • Consumers and providers accumulate the number of calls and call time in memory, and send statistical data to the monitoring center every minute. (It can be seen in the visual interface of dubbo control center)

Dubbo principle:

ConfigServer : The configuration center will perform a real-time heartbeat detection with each Server/Client (because they are all established Socket long connections), such as every few seconds. Collect the information of the services provided by each Server and the information of each Client, and organize a list of services, such as:

Insert picture description here
When a server is unavailable, then update the serverAddressList corresponding to the affected service, that is, kick the server out of the serverAddressList (delete it from the address list), and push the serverAddressList to all the clientAddressLists of these affected services Client. For example: 192.168.0.3 hangs up, then UserService and ProductService serverAddressList must delete 192.168.0.3, and at the same time tell the new list to the corresponding Client 172.16.0.1, 172.16.0.2, 172.16.0.3; correspondingly, when a certain If the client hangs up, then update the clientAddressList corresponding to the affected service.
ConfigServer can provide a web management interface based on the service list to view the provider and user of the management service. When a new Server is added, since it will actively contact ConfigServer, and ConfigServer will actively send this information to the Client, so when a new Server is added, you only need to start the Server, and then within a few seconds, the Client will use it. The service it provides

Client : The machine that calls the service. When each Client starts, it actively establishes a long Socket connection with ConfigServer, and sends its own IP and other corresponding information to ConfigServer.
When the Client uses the service, it obtains the service provider information from the ConfigServer according to the service name (so that ConfigServer knows which Clients are currently using a certain service). After the Client obtains the service provider information, it establishes a connection with them. , You can call the service directly later. When there are multiple service providers, the Client performs load balancing according to certain rules, such as polling, random, and weighted. Once the service provider used by the client changes (the service provider is added or deleted), ConfigServer will push the latest service provider list to the client, and the client will follow the latest service provider list The connection is re-established, the newly added provider establishes the connection, and the deleted provider discards the connection.

Server : The machine that really provides services. When each server starts, it actively establishes a long connection with ConfigServer, and sends its own IP, service name, port and other information directly to ConfigServer, and ConfigServer will collect it from each server. Service information.

advantage:

  • As long as the ConfigServer is good when the Client and Server are started, the service can be invoked. If the ConfigServer hangs later, it will only affect the service provider changes after the ConfigServer hangs, and the Client cannot perceive this change.
  • Each time the Client calls the service, it does not go through the ConfigServer. The Client just establishes contact with it and obtains the list of service providers from it.
  • Invoking service-load balancing: When the client invokes a service, it can invoke services among multiple service providers in turn according to rules.
  • Service Provider-Disaster Recovery: When a Server is down, the Client can still call the service correctly, provided that the service has at least 2 service providers, and the Client can quickly perceive the change of the service provider and make Corresponding response.
  • Service Provider-Extension: It is easy to add a service provider, and Client will quickly perceive its existence and use it.

Dubbo advantages and disadvantages:

Advantages:
a) Transparent remote method calls, call remote methods like local methods
b) Have software load balancing and fault tolerance mechanism, which can replace hardware load balancing such as nginx lvs
c) Service center automatic registration and configuration management, the registration center is based on Interface automatic query provider ip
d) Provides complete service interface management and monitoring

Disadvantages:
only supports java language

It is worth noting that the service information of dubbo in zookeeper is persistent information, and the interface information is temporary. For knowledge of zookeeper, please refer to my previous articles

Five Dubbo project construction

Upload my demo to my code cloud: Gitee address

Guess you like

Origin blog.csdn.net/weixin_44726976/article/details/109605511