Service registration and service discovery - - Eureka use

A, Spring Cloud Netfl l ix
The project is Spring Cloud core subprojects, is the encapsulation of the Netflix series of open source products. It is Spring
provides integrated self-configuring Boot application, only need a few simple annotations, you can quickly apply Spring Cloud in the
use of.
The main module include:
service discovery Register (Eureka)
client load balancing (Ribbon)
circuit breaker (Hystrix)
intelligent routing (Zuul)
Open Source Address:
http://netflix.github.io/
https://github.com / Netflix
Second, the service registration and service discovery
call relations Description:
1. the service provider when you start, registration services they provided to the registry.
2. Consumer Services at startup, you need to subscribe to the service registry.
3. The registry returns the address of the service provider to the consumer.
4. The service consumer calls from consumers in provider address.
note! The following refers to the server: registry, client means: providers and consumers
Third, how to use Eurea ka conduct service registration and discovery
11, the server add-dependent
Spring Cloud Tutorial

<dependency>
<the groupId> org.springframework.cloud </ the groupId>
<the artifactId> Starter-Spring-Cloud-Eureka-Server </ the artifactId>
</ dependency>
2 2, add the configuration server
# server (eureka default port: 8761)
server.port = 8761
# the Spring
spring.application.name the Spring-Cloud-Server =
# Eureka
# is registered to Eureka
eureka.client.register-with-Eureka = false
# whether to obtain registration information from Eureka
eureka.client.fetch -registry = false
address # eureka server (note: the rearmost address / eureka / this is a fixed value)
eureka.client.serviceUrl.defaultZone = HTTP: // localhost: $ {} the server.port / eureka /
. 3. 3, server add annotations
@EnableEurekaServer
4 4, add clients rely
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
5 5 、客户端添加配置
提供者
# server
server.port=7777
# spring
spring.application.name=spring-cloud-provider
# eureka
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
消费者
# server
server.port=8888
# spring
spring.application.name=spring-cloud-consumer
# eureka
Spring Cloud 教程


= HTTP eureka.client.serviceUrl.defaultZone: // localhost: 8761 / Eureka /
6 6, the client add annotations
@EnableEurekaClient
Note:
!. EMERGENCY EUREKA MAY BE Incorrectly the INSTANCES the ARE CLAIMING the WHEN THEY'RE UP the NOT
renewals the ARE LESSER THAN THRESHOLD the INSTANCES the aRE tHE HENCE the NOT the AND BEING JUST EXPIRED
the TO bE SAFE.
analysis: Eureka is due to enter the protected mode.
In protected mode, Eureka Server will try to protect its information service registry, temporary cancellation of service will not be in the registry
service.
Fourth, the basic process:
1, the leftmost client (ie service providers) to initiate us-east-1c registration request;
2, Eureka Server cluster two other node (us-east-1d and us-east-1e be replicate copy);
3, Fig delegated two client (a service consumer), respectively, to obtain registration information and get Registry to three server.
Five, and contrast and r Zookeeper
P CAP theory 11, distributed systems:
consistency (C): time data on all nodes synchronize.
Availability (A): you can receive a response to each request, regardless of success or failure response.
Spring Cloud Tutorial


Partition fault tolerance (P): The system should be able to continue to provide services, even if the internal system message loss (partition).
Since the partition in the fault-tolerant distributed system must be guaranteed, so we can only trade-off between the A and C.
The Zookeeper ensure that CP, and Eureka is the AP.
2 2, r Zookeeper ensure CP
ZooKeeper is CP, i.e., any time access ZooKeeper request to get the same result, the data and the system
network segmentation fault tolerant, but it can not guarantee the availability of each service request (Note: It was in extreme environments,
ZooKeeper may drop some requests, consumers need to request the program to get results).
For example: When the master node because the network lost contact with other nodes failure, the remaining nodes will be leader re-election
move. The problem is that the election leader too long, 30 ~ 120s, and the entire cluster zk are not available during the elections, which
led to paralysis during the electoral registration services.
3 3, a Eureka ensure the AP
Eureka understand this, so the design will give priority to ensuring availability. We can tolerate registry returned a few
minutes before registration information, but can not accept the services directly down out is not available. In other words, the availability of Service registration to
seek higher than consistency.
If the service node Eureka lost a lot of heartbeat connection in a short time (Note: It may happen a network failure), then the
Eureka node will enter into "limp home mode", while preserving those services Registration Information "heartbeat death" does not expire. at this time,
The Eureka node for the new service also provides registration services for the "death" remain, as well as to prevent their client
initiated the request. When the network fault recovery, the Eureka exit node "self-protection mode." Eureka's philosophy is at the same time
retain the "good data" and "bad data" is better than losing any data to be better.
44, summary
Eureka as a simple service registry for more than a zookeeper, "professional", because the registration service is more important is
availability, we can accept short-term reach the consistency of the situation.
Of course, this also depends on the specific usage scenarios.
java architect Video: http://www.angelasp.com/news/20196231880.html

Published 13 original articles · won praise 4 · Views 2771

Guess you like

Origin blog.csdn.net/Angel_asp/article/details/96613450