Search code examples
spring-cloudnetflix-eurekaspring-cloud-netflix

Dynamically update Eureka instance metadata


When Spring Cloud Eureka instance starts I can define some instance metadata statically (in eureka.instance.metadataMap.* in my application.yml) or dynamically (using EurekaInstanceConfigBean for example). But once instance is registered, this metadata no longer updates in Eureka after I update the config bean. Is there a way to define some metadata that will dynamically update in Eureka? So Eureka will work kind of like a key-value storage for each instance.


Solution

  • If you want to update any metadata from eureka client for itself, just use com.netflix.appinfo.ApplicationInfoManagerobject and call registerAppMetadata(Map<String, String>). If so, this info will be updated in Eureka Server usually soon or at least in 30sec.You can use DI to get the instance of ApplicationInfoManger.

    If you want to update metadata for other service instance, just invoke REST API like below to eureka server.

    PUT /eureka/apps/appID/instanceID/metadata?key=value