0

We're using Spring Cloud Angel.SR6 with Netflix Eureka and Spring Config Server. One of our microservices is a distributed system that uses Eureka as a discovery mechanism to find peers. In order to start up the system in the correct way when multiple instances are started in parallel, we would like to know which node started first. The application information in Eureka contains a few different timestamps, but they change when the Eureka client updates the status so it seems that we can't rely on them.

Our idea now is to have the application register its own boot timestamp in the Eureka metadataMap which we have been able to accomplish using the EurekaInstanceConfigBean. With this approach however, the timestamp is added too late in the process. The instances initially appear in Eureka without the timestamp, which is not good enough for us (and even if it would be, it takes to long to be a nice solution).

What we are trying to do instead is to get the timestamp included in the initial Eureka registration. Properties declared in bootstrap.properties are included, so if we could somehow get the timestamp in here everything would work:

eureka.instance.metadataMap.bootTimestamp=<here we want the timestamp>

We have tried to add a custom PropertySourceLocator using the approach mentioned in the Spring Cloud Documentation, but still no luck. The initial Eureka registration happens before the the PropertySourceLocator is initialized which again is too late.

How can we get the boot timestamp into the environment before the initial Eureka registration so the application never appears in Eureka without a timestamp?

Jon Ekdahl
  • 382
  • 1
  • 3
  • 11

2 Answers2

0

We found a not altogether satisfying work-around, so I'm posting this in somebody finds it useful. By passing a timestamp in an environment variable or a system property we are able to include it in the initial registration of metadata in Eureka.

Command line (assuming Linux/bash):

BOOT_TIMESTAMP=$(date +%s%3N) java ...

bootstrap.properties:

eureka.instance.metadataMap.bootTimestamp=${boot.timestamp:0}
Jon Ekdahl
  • 382
  • 1
  • 3
  • 11
0

you can set an evn Property by using System.setProperty when the application gets started. and after that you can use it through the property file like below.

    public static void main(String[] args) {
        System.setProperty("APP_TIMESTAMP", String.valueOf(System.currentTimeMillis())); //this is the line to set the time that the application gets started.
        SpringApplication.run(UseServiceApplication.class, args);
    }

usage of env value in property file (i have used yml file here.)

eureka:
  instance:
    metadata-map:
      timestamp: ${APP_TIMESTAMP}
Mafei
  • 3,063
  • 2
  • 15
  • 37