2
votes

Good morning

I created a microservice in Spring Boot using Netflix Eureka, everything is working perfectly and it ends up running on the next URI:

-> http://localhost:8082/catalogs

My question is whether instead of using the localhost and port, I can use the spring.application.name getting:

-> http://catalog-service/catalogs

If anyone knows how to do that and share it, I'd be grateful.

Below follows the application.properties of Eureka Server and Eureka Client:

Server:

```spring.application.name=eureka-server 
server.port=8761

#don't register itself as a client
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
logging.level.com.netflix.eureka=ON
logging.level.com.netflix.discovery=ON```

Client:

```#Eureka
spring.application.name=catalog-service
server.port=8762
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.client.service-url.default-zone=http://localhost:8761/eureka/
instance.preferIpAddress=true```

Thank you for the help

1
Hi @tksilicon Thanks for your help, but I don't want to get or change the server.port and server.host. I want to access my microservice without using them, just using a custom name in my URI.Mr Spring Boot
@MrSpringBoot I have the same issue. How do you fix it? Which code snippets should you use in application.properties file?Tony Brand

1 Answers

0
votes

You are trying to route the service calls through Eureka , But Eureka is like a directory service ,it maintains details of all applications whoever registers with it.

If you want to route your service calls or in your case call the API with just the name of your client you can use Zuul API gateway.

How does it works?

I'll give an basic idea of how it is gonna works ,you can discover more about it in details.

Instead of calling your client you will call zuul with your client name, zuul will get the host and port detail of your client from eureka and route the call to your client. Below link has the example of an sample application of zuul with Eureka.

https://piotrminkowski.com/2017/02/05/part-1-creating-microservice-using-spring-cloud-eureka-and-zuul/