This is the 14th day of my participation in the August More Text Challenge

preface

Based on the basic components and version dependencies of SpringCloud from a few days ago, we will officially enter SpringCloud. In this chapter, we will talk about Eureka, one of the so-called service registries, which will be listed in subsequent chapters.

Server registry technologies

technology Belongs to Start the introduce
Eureka Netflix Maven rely on As we learned, it is the earliest service registry based on SpringCloud
Zookeeper Apache inClose the netdownload It is an important component of Hadoop and Hbase. He can manage services and discover services. He can synthesize error-prone services into a stable set of services
Consul Hashicorp inClose the netdownload Currently the main function is service discovery, other additional functions, such as automatic orchestration, key-value database, etc
Nacos alibaba Maven rely on This is an upgrade of Eureka technology from Alibaba, currently used in SpringCloudAlibaba, it is very easy to use and the service is very stable (currently used in the new generation of distributed systems).

Eureka knowledge

1. Service registration

Service registration: When the Eureka client registers with the Eureka Server, it provides its own metadata, such as IP address, port, health indicator URL, home page, and so on

2. Service renewal

Service renewal: refers to the heartbeat of the service, which is 30 seconds by default. The customer will send a heartbeat every 30 seconds to renew the service and inform Eureka Server that the service is in normal use. Otherwise, his registration information will be removed.

3. The service is offline

Service offline: The Eureka client sends an offline request to the Eureka server when the program is shut down.

4. Obtain the registration list

Fetch list information: Eureka’s fetch- Registry is the server information that the discovery service exposes to the registry Eureka client. This can be set to true in the Settings, or false if Eureka Server does not need to be exposed to other servers.

5. Service elimination

Service deletion: If the Eureka client does not send heartbeat messages to the Eureka Server for 90 consecutive seconds, the Eureka Server will delete the service instance from the service registry

6. Self-protection mode

Self-protection Mode: Self-protection Mode If 85% of the clients do not have normal heartbeat communication within 15 minutes, Eureka considers that the network between the client and the registry is faulty, and the Eureka Server automatically enters self-protection mode. No service is removed. When the network is recovered, the node automatically exits the self-protection mode.

case

The service side

In our application.yml file, we can configure the following

Client: register-with-eureka: port: 7001 eureka: instance: hostname: eureka7001.com False #false indicates that I am the registry myself. My job is to maintain the service instance. I do not need to retrieve myself (the current service). Enable-self-preservation: false eviction- interval-timer-in-MS: 2000Copy the code

The startup is as follows:

The client

See comments in the code for specific explanations

server: port: 8001 spring: application: name: Eureka server will randomly assign a name to the Eureka server if the name is not specified. Sampler: # Values of sampling rate are between 0 and 1, and 1 indicates total sampling probability: 1 Com. Alibaba. Druid. Pool. DruidDataSource # current data source type driver operation - class - name: com. Mysql. Cj.. JDBC driver # mysql driver class url: jdbc:mysql://localhost:3307/eight_tow_payment? useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC username: root password: eureka: client: Register-with-eureka: true #true indicates to register oneself with the registry. Default true fetch-registry: True # true said myself is to maintain service instance, and need to retrieve your (current) default true service - url: defaultZone: http://localhost:7001/eureka # check address # defaultZone: http://eureka7001.com:7001/eureka, http://eureka7002.com:7002//eureka # check address instance: the instance - id: payment8081 prefer-ip-address: IP #Eureka specifies the time that the client waits for after receiving the last heartbeat. The default value is 90 seconds. If the timeout period expires, the service will be deleted. 2 #Eureka Interval for sending heartbeat messages from the client to the server, in seconds. The default value is 30 seconds. Lease -renewal-interval-in-seconds: 1 mybatis: mapper-locations: classpath*:mapper/*.xml type-aliases-package: com.wzy.springcloud.entitiesCopy the code

This configuration involves myBatis students who do not understand can be moreThis articleSo let’s go back.

conclusion

With written with the above case, we will see Eureka configuration is very easy, and it is also very fast, inside some of the configuration in our yml file can be configured, the service registry as an agent, he will be unified to manage we all had a client, and real-time system and monitor our client state changes.

Handwriting is not easy, we still need to give a lot of praise and attention, the students who like technology do not be impatient, this series of articles I will gradually launch, we all study together.