繁体   English   中英

如何使用eureka.client.service-url: spring cloud中netflix eureka的属性

[英]How to use eureka.client.service-url: property of netflix eureka in spring cloud

我正在尝试在其中一个微服务中添加 Eureka 客户端,但我无法弄清楚我是否可以使用 service-url。

我正在使用 Spring-cloud 的 Greenwich.SR1 版本。

下面是我的 application.yml

spring:
  application:
    name: stock-service

server:
  port: 9901

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url: http://${eureka.instance.hostname}:9902/eureka/

我试图搜索它,但到处都在使用此版本不支持的旧方法:

旧方式:

eureka:         #tells about the Eureka server details and its refresh time
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka/ 

有人可以帮忙吗?

最后,我找到了配置:

spring:
  application:
    name: stock-service

server:
  port: 9901

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      default-zone: http://localhost:9902/eureka

我刚刚在Spring Cloud Hoxton.SR4尝试了这个配置,但它不起作用。 然后我找到了正确的方法(至少对我来说):

spring:
  application:
    name: hello-world-server

server:
  port: 8010

eureka:
  client:
    service-url:
      defaultZone: http://localhost:9001/eureka/

启动客户端应用程序后,我们可以看到以下日志:

2020-05-02 16:39:21.914  INFO 27104 --- [           main] c.n.d.DiscoveryClient                    : Discovery Client initialized at timestamp 1588408761914 with initial instances count: 0
2020-05-02 16:39:21.915  INFO 27104 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application HELLO-WORLD-SERVER with eureka with status UP
2020-05-02 16:39:21.915  INFO 27104 --- [           main] c.n.d.DiscoveryClient                    : Saw local status change event StatusChangeEvent [timestamp=1588408761915, current=UP, previous=STARTING]
2020-05-02 16:39:21.916  INFO 27104 --- [nfoReplicator-0] c.n.d.DiscoveryClient                    : DiscoveryClient_HELLO-WORLD-SERVER/tumbleweed:hello-world-server:8010: registering service...

和服务器端:

在此处输入图片说明

有用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM