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

What is the use of Eureka framework

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail what the Eureka framework is used for. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

Eureka Registry/Service Discovery Framework

Eureka is a service discovery framework developed by Netflix. It is a REST-based service that is mainly used to locate middle-tier services running in AWS domain for the purpose of Load Balancer and failover of middle-tier services. SpringCloud integrates it into its subproject spring-cloud-netflix to enable SpringCloud's service discovery capabilities.

Eureka consists of two components: Eureka Server and Eureka Client.

Eureka Server provides service registration service. After each node is started, it will be registered in Eureka Server. In this way, the service registry in Eureka Server will store the information of all available service nodes, and the information of service nodes can be visually seen in the interface.

Eureka Client is a java client designed to simplify interaction with Eureka Server. The client is also a built-in Load Balancer that uses round-robin load algorithms.

After the application is started, it will send heartbeats to Eureka Server. The default period is 30 seconds. If Eureka Server does not receive heartbeats from a certain node within multiple heartbeat cycles, Eureka Server will remove this service node from the service registry (default 90 seconds).

Eureka servers synchronize data through replication. Eureka also provides a client-side caching mechanism. Even if all Eureka servers hang up, clients can still consume APIs of other services using the information in the cache. To sum up, Eureka ensures high availability, flexibility and scalability of the system through heartbeat checking, client caching and other mechanisms.

How do I build Eureka Server ?

Add dependencies (here Maven is an example)

org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASE org.springframework.cloud spring-cloud-starter-netflix-eureka-server Create the Eureka Server main runtime package com.liang.cloud;import org.springframework.boot.SpringApplication;import org.springframework.boot. autofigure.SpringBootApplication;import org.springframework.cloud. netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer //plus the Enable Eureka service annotation (label it Eureka service)@SpringBootApplicationpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class,args); }}

Eureka Server comes with a Web home page, accessed by default at http://localhost:8761/.

The Eureka service has no background storage, but all service instances in the registry must send heartbeats to keep their registration up to date (and thus can be done in memory). The client also has an Eureka registered memory cache (so they don't have to go into the registry for every request to the service).

By default, each Eureka server also has an Eureka client and requires (at least one) service URL to locate it. If you do not provide this service, the service will continue to run, and the output error log may interfere with you (if your port is not 8761 and you are configured with another serviceUrl, this error log will continue to be generated. If you are configured by default, this error will only be reported once, and then you can connect to yourself successfully after starting it).

standalone configuration

application.yml(single Eureka service configuration), as follows:

server: port: 8761 #port spring: application: name: eureka-server #application name, eureka: client: register-with-eureka: false #Register your information to EurekaServer, default is true fetch-registry: false #Pull information about other services, default is true service-url: # EurekaServer address, now its own address, if it is a cluster, you need to add the address of other servers. defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

Note that serviceUrl points to the same host as the local instance.

cluster configuration

application.yml(two Eureka service configurations), as follows

---server: port: 6001spring: profiles: eureka6001eureka: instance: hostname: eureka6001.com client: register-with-eureka: false #Register your information to EurekaServer, default is true fetch-registry: false #Pull information about other services, default is true service-url: # EurekaServer address, now its own address, if it is a cluster, you need to add the address of other servers. defaultZone: http://eureka6002:6002/eureka---server: port: 6002spring: profiles: eureka6002eureka: instance: hostname: eureka6002.com client: register-with-eureka: false #Register your information to EurekaServer, default is true fetch-registry: false #Pull information about other services, default is true service-url: # EurekaServer address, now its own address, if it is a cluster, you need to add the address of other servers. defaultZone: http://eureka6001:6001/eureka

In the previous example, we had a YAML file, and by running the server in different Spring profiles, we could run the same Eureka service on two hosts (eureka6001 and eureka6002). You can use this configuration to test peer awareness on a single host by manipulating/etc/hosts to resolve host names (which is not of much value in a production environment). In fact, eureka.instance.hostname if you are running on a computer whose hostname you know (by default, the hostname of that machine is used). Eureka springcloud Application Example www.1b23.com

You can add multiple Eureka services to a cluster, and they can register synchronously with each other as long as they are all communicating connections. If physically separated (within a data center or between multiple data centers), they can register synchronously with each other as long as they are all directly connected to each other.

Eureka Client Connection Eureka Server Cluster Configuration

application.yml(two Eureka service connection addresses need to be added, separated by commas), as follows

eureka: client: serviceUrl: defaultZone: http://eureka6001.com/eureka/,http://eureka6002.com About "Eureka framework what is useful" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

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

Development

Wechat

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

12
Report