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
Provide the service side implements the interface
Exposing services using Spring configuration statement
provider.xml (omitted various properties beans tag)
Spring loaded configuration
Consumer Services
consumer.xml
Spring loaded configuration and remote service call
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
- RoundRobin LoadBalance, random, random probability according to weight setting.
- RoundRobin LoadBalance, polling, by convention right after reset polling rate.
- 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.
- Request ConsistentHash LoadBalance, consistency Hash, the same parameter is always sent to the same provider.
Now the overall architecture is shown below (assuming that the service consumer to order service, the service provider for customer service):
So what is the problem?
- When the service provider add nodes, you need to modify the configuration file
- 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
Now we look at the official website of Dubbo Dubbo introduction to drawing, there is no us and drew very similar
Node Role Description
Call relationship Description
- Service container is responsible for starting (in the above example is the Spring container), is loaded, run service provider.
- Service provider when you start, registration services they provided to the registry.
- Consumer services at startup, you need to subscribe to the service registry.
- 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.
- Service consumers, providers from the list of addresses, soft load balancing algorithm, choose a provider call, if the call fails, then select another call.
- 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
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
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
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
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