Closed HaojunRen closed 3 years ago
Duplicates #682
Yeah, it works fine with ConsulServiceInstance
ConsulServiceInstance consulServer = (ConsulServiceInstance) server;
Map<String, String> metadata = new HashMap<String, String>();
List<String> tags = consulServer.getTags();
for (String tag : tags) {
String[] tagArray = StringUtils.splitByWholeSeparator(tag, "=");
metadata.put(tagArray[0], tagArray[1]);
}
but i want to get metadata of local service just like following code:
@Autowired
protected Registration registration;
public Map<String, String> getMetadata() {
return registration.getMetadata();
}
it can't work
BTW, i think it is better to convert tag list to tag map in consulServer.getMetadata
method
I don't think it is. Tags as metadata was a workaround.
ConsulServiceRegistration has access to a NewService object which has access to tags
Now current solution is not so friendly and compatible to customers if they upgrades version from low Spring Cloud version
registration.getMetadata() -> not return customer's metadata consulServer.getMetadata() -> not return customer's metadata
The previous version had a flag to allow migration to metadata from tags
I want to keep the same behavior with EurekaServiceInstance and ZookeeperServiceInstance. Why getMetadata is work fine in EurekaServiceInstance and ZookeeperServiceInstance, but failed in ConsulServiceInstance?
Eureka already had a map as metadata. Zookeeper serialized anything we wanted so we made it a map. Consul, early on only had tags, then it got real metadata. So as part of our breaking changes in our major release we migrated off of the hack.
It works with following formats input: spring.cloud.consul.discovery.metadata.version=1.0 spring.cloud.consul.discovery.metadata.region=dev spring.cloud.consul.discovery.metadata.env=env1
But i still suggest that new spring cloud consul can be compatible with old format input: spring.cloud.consul.discovery.tags=version=1.0,region=dev,env=env1
Hello Team,
It seems that the followings config of tags can't work in 2020 version, but it works fine in old Spring Cloud version
Would you please tell me how to set tags in Spring Cloud 2020? Thanks a lot