Dynamically updating metadata of an Eureka instance

When Spring Cloud Eureka instance starts, I can define some metadata of the instance statically ( eureka.instance.metadataMap.*

in mine application.yml

) or dynamically (using EurekaInstanceConfigBean

for example). But once the instance is registered, this metadata is no longer updated in Eureka after updating the bean configuration. Is there a way to define some metadata that will be dynamically updated in Eureka? Thus, Eureka will act as a keyed store for each instance.

+3


source to share


1 answer


If you want to update any metadata from the eureka client for yourself, just use the object com.netflix.appinfo.ApplicationInfoManager

and call registerAppMetadata(Map<String, String>)

. If so, this information will be updated on the Eureka server usually soon, or at least 30 seconds later. You can use DI to get an instance of ApplicationInfoManger.

If you want to update the metadata for another instance of the service, just call the REST API as shown below to the eureka server.



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

      

+4


source







All Articles