Interviewer: only Dubbo not do? Why should there Zookeeper?

16826084-dc09959f3da153aa.jpg

Point of attention, do not get lost; continually updated Java-related technologies and information architecture thermal paper! ! !

Introduction

Micro fire service is relatively recent concept, and micro-current mainstream service framework has Dubbo and Spring Cloud, both in order to solve the various problems encountered micro-services arising from the problem that is encountered is the same, but solving strategies is different, so it is often used to compare two frameworks. Not used Dubbo little friends do not worry, in fact, quite simple Dubbo, after reading this article you can grasp a general, not the code is important, but the mind.

Dubbo achieve service invocation by RPC manner, i.e. the client and server share a common interface (interface a labeled jar package, the package is introduced in this jar client and server), the client interface for writing calls for the server Interface write achieve network communication to the middle of the frame to achieve, I would like to see in-depth understanding of recommended reading. There GitHub Code description link address

Getting Started

service providers

Define the service interface

16826084-938bda44fe0fae98.png

Provide the service side implements the interface

16826084-9498797ce691575d.png

Exposing services using Spring configuration statement

provider.xml (omitted various properties beans tag)

16826084-74fa4ca744cadecf.png

Spring loaded configuration

16826084-3fe44fc860bf7423.png

Consumer Services

consumer.xml

16826084-8248869a6b52b194.png

Spring loaded configuration and remote service call

16826084-d638916238695b2f.png

This is a typical point to point service call. Of course, we have to high availability, you can configure multiple service providers in consumer.xml and configure load balancing policy response

A plurality of service of the caller comsumer.xml <dubbo: reference> add multiple addresses url attribute tag, can be separated by semicolons

Load balancing policy configured in <dubbo: reference> comsumer.xml Tags loadbalance attribute to increase, the value of four types may be as follows

  1. RoundRobin LoadBalance, random, random probability according to weight setting.
  2. RoundRobin LoadBalance, polling, by convention right after reset polling rate.
  3. LeastActive LoadBalance, a minimum number of active calls, the same random number is active, the number of active call count means before and after difference.
  4. Request ConsistentHash LoadBalance, consistency Hash, the same parameter is always sent to the same provider.
16826084-4e0fe1b0093e9370.png

Now the overall architecture is shown below (assuming that the service consumer to order service, the service provider for customer service):

16826084-4417ba422733b78e.png

So what is the problem?

  1. When the service provider add nodes, you need to modify the configuration file
  2. When one service provider is down, the service consumer does not perceive a timely manner, but also to send a request to the service downtime

This time you have introduced a registration center

Registry

Dubbo currently supports four registration centers, (multicast zookeeper redis simple) recommended Zookeeper registry, this paper talk about the realization of service registration and discovery with a zookeeper (knock on the blackboard, yet another zookeeper useful), the following general process

16826084-60be9eb7f5557498.png

Now we look at the official website of Dubbo Dubbo introduction to drawing, there is no us and drew very similar

16826084-1ffb06b0b7ae44bb.png

Node Role Description

16826084-8ca94389f7a5d42b.png

Call relationship Description

  1. Service container is responsible for starting (in the above example is the Spring container), is loaded, run service provider.
  2. Service provider when you start, registration services they provided to the registry.
  3. Consumer services at startup, you need to subscribe to the service registry.
  4. Registry return address list service providers to consumers, if there is a change, the registry will be based on long push to change the data connection to the consumer.
  5. Service consumers, providers from the list of addresses, soft load balancing algorithm, choose a provider call, if the call fails, then select another call.
  6. Service consumers and providers, in memory of the cumulative number of calls and call time, time sent once per minute statistical data to the monitoring center.

To use the registry, simply change the following provider.xml and consumer.xml

16826084-ab3b0451bfda9b29.png

If zookeeper is a cluster, multiple addresses separated by commas

<dubbo:registry protocol="zookeeper" address="192.168.11.129:2181,192.168.11.137:2181,192.168.11.138:2181"/>

The direct connection arranged in a manner to remove consumer.xml

16826084-7a637c01ea5537fb.png

Registration information on how to save the zookeeper?

After starting the services described above, we have observed more than a zookeeper of the root node and other dubbo, illustrated as follows

16826084-a3eb46da5520bb9e.png

Finally, a small series of nodes 192.168.1.104 is the network address, you can configure tasks and a localhost above results, we can think about why I put the last node marked as green. Yes, the last node is a temporary node and other nodes are persistent node, so that when the service is down, the node will automatically disappear, no longer available, consumers will no longer service requests. If you deploy multiple DemoService, the following providers have several nodes, a service node holds address of a DemoService

In fact, a zookeeper cluster multiple applications can be public, such as clusters and small series Storm Dubbo is a zookeeper cluster configuration, why? Because different frameworks will be built on different nodes zookeeper, independently of each other. The Dubbo creates a / dubbo node creates a Storm / storm node, as shown in

16826084-19f286654ad47ccb.png

Point of attention, do not get lost; continually updated Java-related technologies and information architecture thermal paper! ! !

Reproduced in: https: //www.jianshu.com/p/f5ddbde05813

Guess you like

Origin blog.csdn.net/weixin_33882452/article/details/91072134