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

Viewed 9955

I am trying to add Eureka client in one of the microservices, but i am unable to figure out if how can I use the service-url.

I am using the Greenwich.SR1 version of spring-cloud.

Below is my 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/

I tried to search it out but everywhere I am getting the old way which is not supported in this version:

Old Way:

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/ 

Could someone help here?

2 Answers

Finally, I find the configuration:

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

I just tried this configuration in Spring Cloud Hoxton.SR4, and it doesn't work. Then I find out the correct way (at least for me):

spring:
  application:
    name: hello-world-server

server:
  port: 8010

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

We could see the logs below after starting your client application:

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...

And the Server side:

enter image description here

It works!

Related