Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to apply SpringCloud Integrated Eureka Registry

Shulou Source: shulou.com Published: 2022-06-01 23:13:24 09月21日 Update

This article focuses on "how to apply SpringCloud to integrate Eureka registry", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to apply SpringCloud to integrate Eureka registry.

Introduction

Eureka, the core component of SpringCloud, provides service registration and service discovery functions to manage various services in distributed systems, such as registration, discovery, circuit breaker, load balancing and so on.

Version Notes SpringCloud:Greenwich.RELEASESpringBoot: 2.1.2.RELEASE implementation steps

1. Introduce dependency

Parent project

Org.springframework.cloud spring-cloud-dependencies Greenwich.RELEASE pom import

Sub-project

Org.springframework.cloud spring-cloud-starter-netflix-eureka-server

two。 Add configuration application.properties

# Project port number server.port=6001 # Project name spring.application.name=service-registry # whether to register yourself as a service in another service registry, whether the default true eureka.client.register-with-eureka=false # synchronizes the service list from other service centers, and whether the default true eureka.client.fetch-registry=false # sets the address to interact with Eureka Server. Both query service and registration service depend on this address. Eureka.client.serviceUrl.defaultZone= http://localhost:${server.port}/eureka/

3. Startup class add startup registry

@ SpringBootApplication @ EnableEurekaServer / / enable the Eureka service public class Application {public static void main (String [] args) {SpringApplication.run (Application.class,args);}} Cluster Registry

In the distributed system, the registry is the most important basic part. In order to prevent the catastrophe caused by the failure of the registry, we must ensure the high availability of the registry. We can use the cluster approach.

1. Create a project

Create 3 projects as described above

Registry-1

Registry-2

Registry-3

two。 Modify the host file of the operating system

Windows system C:\ Windows\ System32\ drivers\ etc\ hosts

Linux system / etc/hosts

Add the following configuration:

127.0.0.1 service-registry1 127.0.0.1 service-registry2 127.0.0.1 service-registry3

3. Configuration file modification

# registry-1.application.properties # Project port number server.port=6001 # Project name spring.application.name=service-registry # Service registries must display settings register-with-eureka and fetch-registry with a value of true Otherwise, the service is unavailable # whether to register itself as a service with another service registry eureka.client.register-with-eureka=true # whether to synchronize the service list from other service centers eureka.client.fetch-registry=true # to set the address to interact with Eureka Server Both query and registration services rely on this address. Eureka.client.serviceUrl.defaultZone= http://service-registry2:6002/eureka/, Http://service-registry3:6003/eureka/ eureka.instance.appname=service-registry # Host name eureka.instance.hostname=service-registry1 # Service Registry address # registry-2.application.properties # Project Port number server.port=6002 # Project name spring.application.name=service-registry # Service Registry must display settings register-with-eureka and fetch-registry with values of true Otherwise, the service is unavailable # whether to register itself as a service with another service registry eureka.client.register-with-eureka=true # whether to synchronize the service list from other service centers eureka.client.fetch-registry=true # to set the address to interact with Eureka Server Both query and registration services rely on this address. Eureka.client.serviceUrl.defaultZone= http://service-registry1:6001/eureka/,http://service-registry3:6003/eureka/ eureka.instance.appname=service-registry # Host name eureka.instance.hostname=service-registry2 # registry-3.application.properties # Project Port number server.port=6003 # Project name spring.application.name=service-registry # Service Registry must display the settings register-with-eureka and fetch-registry with a value of true Otherwise, the service is unavailable # whether to register itself as a service with another service registry eureka.client.register-with-eureka=true # whether to synchronize the service list from other service centers eureka.client.fetch-registry=true # to set the address to interact with Eureka Server Both query and registration services rely on this address. Eureka.client.serviceUrl.defaultZone= http://service-registry1:6001/eureka/,http://service-registry2:6003/eureka/ eureka.instance.appname=service-registry # Host name eureka.instance.hostname=service-registry3 Note

1. Mutual registration of service registry clusters must be enabled.

Register-with-eureka: true fetch-registry: true

two。 The spring.application.name of the service registry cluster must be the same

3.eureka.client.serviceUrl.defaultZone: localhost cannot appear. Be sure to use host to specify the host name.

At this point, I believe you have a deeper understanding of "how to apply SpringCloud integrated Eureka registry". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Service project address name system query host slogan service center query service cluster synchronization application configuration content distributed file learning practical deeper Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn Shulou Information Docker Linux