how use application name replace ip:port about spring cloud eureka?

Viewed 1515

spring cloud eureka question: there are 3 microservices, 1 eureka server, 2 eureka client;

  1. microservice A,B use annotation @EnableEurekaClient;

  2. microservice A have a RESTful api "http://localhost:8080/hi". the api return "hello".

  3. now, I call the api , use url "http://client/hi", but it doesn't work.

  4. how use application name replace ip:port about spring cloud eureka?

the bootstrap.yml content:

spring:
  application:
    name: client

eureka:
  client:
    service-url:
      defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/
2 Answers

I'm using RestTemplate, but i got Connection timed out: connect after put serviceName instead of localhost:port

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
    return new RestTemplate();
}

call API:

FraudCheckResponse fraudCheckResponse = customerConfig.restTemplate().getForObject(
            "http://fraud/api/v1/fraud-check/{customerId}",
            FraudCheckResponse.class,
            customer.getId()
    );
Related