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.
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ In the preceding example, "defaultZone" is a magic string fallback value that provides the service URL for any client that does not express a preference (in other words, it is a useful default).
To include the Eureka Client in your project, use the starter with a group ID of org. springframework. cloud and an artifact ID of spring-cloud-starter-netflix-eureka-client . See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
2.6 When to Prefer IP Address instance. preferIpAddress to true and, when the application registers with eureka, it uses its IP address rather than its hostname. If the hostname cannot be determined by Java, then the IP address is sent to Eureka. Only explict way of setting the hostname is by setting eureka.
Hit the URL http://localhost:8761/ in your web browser and you can see the Eureka Client application is registered with Eureka Server. Now hit the URL http://localhost:8080/ in your web browser and see the Rest Endpoint output.
If you want to update any metadata from eureka client for itself, just use com.netflix.appinfo.ApplicationInfoManager
object 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With