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

Server of spring cloud eureka

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

Share

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

I. Dependency

org.springframework.cloud spring-cloud-starter-netflix-eureka-server 2.0.0.RC1

II. Add comments to startup class

@SpringBootApplication@EnableEurekaServerpublic class ServiceRegisterCenterDemoApplication { public static void main(String[] args) { SpringApplication.run(ServiceRegisterCenterDemoApplication.class, args); }}

III. Configuration of stand-alone registry

spring.application.name=service-register-center-demoserver.port=19001eureka.instance.hostname=localhosteureka.instance.app-group-name=test_groupeureka.instance.appname=register_centereureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/statuseureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

You can access the service through http://localhost:19001/. Below:

Check health checks at http://localhost:19001/actuator.

Note:

eureka.instance.appname corresponds to the application name under instances in the web panel;eureka.client.register-with-eureka=false indicates that this instance will not be registered to the service center. Otherwise, it will be registered. This can be viewed through the instances list in the dashboard;eureka.client.fetch-registry=false indicates whether the list of services is pulled from the registry; for a stand-alone registry, whether there is no backup (replication) node. In the panel, registered-replicas, available-replicas and available-replicas under General Info are all empty. It can be seen that the registration service center can also be a client, and you can also register your own instance to the service center.

IV. Configuration of multiple peer registries

instance 1

spring.application.name=service-register-center-demoserver.port=19001eureka.instance.hostname=peer1eureka.instance.app-group-name=test_groupeureka.instance.appname=register_center1eureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/status#eureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://peer2:19001/eureka/

instance 2

spring.application.name=service-register-center-1-demoserver.port=19002eureka.instance.hostname=peer2eureka.instance.app-group-name=test_groupeureka.instance.appname=register_center2eureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/status#eureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://peer1:19002/eureka/

Note:

For a stand-alone configuration with multiple peer nodes, the hosts file needs to be modified; different from the stand-alone configuration, eureka.client.serviceUrl.defaultZone needs to be configured with each other, and multiple (comma separated) can be configured.

V. Description of configuration parameters

eureka.instance.hostname can be left unset. By default, it will be the host name in serviceUrl, such as localhosteureka.client.serviceUrl.defaultZone. eureka.instance.hostname can be used, or IP can be set directly;eureka.instance.appname indicates the instance name. It can also be omitted, and the value of spring.application.name is used;eureka.client.register-with-eureka=false means that this instance will not be registered to the service center. Otherwise, it will be registered. This can be viewed through the instances list in the dashboard;eureka.client.fetch-registry=false indicates whether to pull the service list from the registry;

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