Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the eureka component in SpringCloud

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

I believe many inexperienced people don't know what to do about how to use eureka components in SpringCloud. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Eureka is developed by Netflix, a REST service-based component for service registration and discovery

It mainly consists of two components: Eureka Server and Eureka Client

Eureka Client: a Java client that simplifies interaction with Eureka Server (usually the client and server in microservices)

Eureka Server: the ability to provide service registration and discovery (usually a registry in a microservice)

Working structure diagram:

When each microservice starts, it registers itself with Eureka Server through Eureka Client, and Eureka Server stores the information of the service.

In other words, the client and server of each microservice will register with Eureka Server, which gives rise to the topic of mutual identification of microservices.

Synchronization: each Eureka Server is also Eureka Client (logical)

The synchronization of the service registry is completed between multiple Eureka Server through replication, resulting in the high availability of Eureka.

Identification: Eureka Client caches information in Eureka Server

Even if all Eureka Server nodes are down, service consumers can still use the information in the cache to find the service provider (the author has tested it myself)

Renewal: microservice sends heartbeat Renew (renewal) message to Eureka Server periodically (default is 30s) (similar to heartbeat)

Renewal: Eureka Server will perform a failure service detection function on a regular basis (default 60s)

It will check the micro-service without Renew for more than a certain period of time (the default is 90s), and will log off the micro-service node when it is found.

Spring Cloud has integrated Eureka into its subproject Spring Cloud Netflix

Eureka Server integration in springCloud

1.pom file configuration

Org.springframework.cloud

Spring-cloud-starter-eureka-server

Org.springframework.boot

Spring-boot-starter-security

2 yml profile

Security: basic: enabled: true user: name: user password: password123server: port: 8761eureka: client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://user:password123@localhost:8761/eureka

3. Startup class

Package com.itmuch.cloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServerpublic class EurekaApplication {public static void main (String [] args) {SpringApplication.run (EurekaApplication.class, args);}}

SpringCloud integrated Eureka client

1.pom file

4.0.0 microservice-provider-user jar microservice-provider-user Demo project for Spring Boot com.itmuch.cloud microservice-spring-cloud 0.0.1-SNAPSHOT UTF-8 UTF-8 1.8 Org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web Com.h3database h3 runtime org.springframework.cloud spring-cloud-starter-eureka org.springframework.boot spring-boot-starter-actuator

Org.springframework.cloud

Spring-cloud-starter-eureka

Org.springframework.boot

Spring-boot-starter-actuator

2.yml profile

Server: port: 7900spring: jpa: generate-ddl: false show-sql: true hibernate: ddl-auto: none datasource: platform: h3 schema: classpath:schema.sql data: classpath:data.sql application: name: microservice-provider-userlogging: level: root: INFO org.hibernate: INFO org.hibernate.type.descriptor.sql.BasicBinder: TRACE org.hibernate.type.descriptor.sql.BasicExtractor: TRACE com.itmuch: DEBUGeureka: client : healthcheck: enabled: true serviceUrl: defaultZone: http://user:password123@localhost:8761/eureka instance: prefer-ip-address: true instance-id: ${spring.application.name}: ${spring.cloud.client.ipAddress}: ${spring.application.instance_id:$ {server.port}} metadata-map: zone: ABC # eureka understandable metadata lilizhou: BBC # No Will affect client behavior lease-renewal-interval-in-seconds: 5

3. Start the client class

Package com.itmuch.cloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClientpublic class MicroserviceSimpleProviderUserApplication {public static void main (String [] args) {SpringApplication.run (MicroserviceSimpleProviderUserApplication.class, args);}} after reading the above, have you mastered how to use the eureka component in SpringCloud? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report