Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Eureka instance Id

I would like to know if it exist a way for an Eureka client to know it actual instanceId (I am looking for a solution that works both on same host and in distributed conf).

So far, I was using my manually defined eureka.instance.instance-id: ${spring.application.name}:${random.int}, but each time I access it value, I get a new one due to the random. So it will always be different from the one that have been generated and gived to the server at registration time.

like image 482
Victor Petit Avatar asked Feb 05 '23 22:02

Victor Petit


1 Answers

Yes, the RandomValuePropertySource is stateless, so you get new value everytime you access that property.

First, you might want to consider using the host:port as the instanceId, no randomness there.

If that's not good enough, Inject EurekaInstanceConfigBean and get the instanceId. (Requires some testing)

Best is to set the instance-id has a system property yourself before SpringApplication.run.

like image 116
lawal Avatar answered Feb 20 '23 15:02

lawal