Spring-cloud-netflix: Adding to eureka metadata dynamically

Created on 11 Nov 2014  路  5Comments  路  Source: spring-cloud/spring-cloud-netflix

I tried to add to the metadata of a service after it was created but I cannot see this data propagated in the discovery of it to other services.

I tried adding a auto wired dependency to

@Autowired
private EurekaInstanceConfigBean eurekaInstanceConfigBean;

Then later I got

Map<String, String> metadata = eurekaInstanceConfigBean.getMetadataMap();

added my own metadata key, value pairs and did a

eurekaInstanceConfigBean.setMetadataMap(metadata);

It does not seem to get propagated. I assumed it was possible but is it?

The reason I am using it is that there are some properties associated with the service that I wanted to pass along and figured that add then this way would work.

question

All 5 comments

@larry13767 It is probably an issue of order. You are probably setting the metadata before Eureka is called. Eureka is contacted in a bean that implements SmartLifecycle. You should set your metadata in a bean in a similar method but that is ordered before the EurekaClientConfiguration.

Thanks for responding.
Ok, understood. So I take it to mean that once you register metadata for a service, it cannot be changed or updated afterwards? I had assumed (and probably wishful hopes) that I could update it and that subsequent service updates would alter the registered metadata for the services. I built this on seeing an add, remove and modified service update ActionType. I thought tat the modified would carry this newer or altered metadata.

The EurekaInstanceConfig is used to initialize the metadata, but I don't think it is the object that is actually sent to the server (that's an InstanceInfo). Try this

Map<String, String> map = ApplicationInfoManager.getInstance().getInfo().getMetaData();
map.put("foo", "bar");

and see if that gets sent to the server on the next heartbeat.

I will try that out, thanks

Is it okay to not call setIsDirty() on InstanceInfo?

Was this page helpful?
0 / 5 - 0 ratings