spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

Support multiple documents in a single YML file / KV

Open springfang opened this issue 9 years ago • 6 comments

I've been using Spring Cloud Config for a while but I'm looking into switching to Consul. Up to this point I have been storing multiple documents in a single YML file and taking advantage of Spring Cloud Config's ability to only add the documents that correspond to the active Spring profiles to the property source, but this does not appear to work with Spring Cloud Consul.

I have tried setting spring.cloud.consul.config.format: YAML and manually putting the multi-document YML files into Consul, as well as using the FILES setting and git2consul to just throw my files into Consul from Git, but in both cases the result is the same: the entire file is added to the property source rather than just the documents corresponding to the active profiles. Consequently, I've had to create new YML files for every profile or multiple KV entries in Consul for each profile (depending on how spring.cloud.consul.config.format is set).

Here's a simple example of the type of file I'm referring to:

server.port: 8999

---
spring.profiles: vm1

server.port: 8110

---
spring.profiles: vm2

server.port: 7013

Currently, I either have to create three separate files when using FILES, or three separate KV entries when using YAML.

springfang avatar Oct 19 '16 21:10 springfang

Just adding in that I've also just stumbled on this and was surprised profiles didn't work the same way as Spring Config. I think the docs are a little confusing, especially around the "profileSeparator: '::'" not working as expected;

peavers avatar Dec 12 '17 22:12 peavers

We have ran into this also since we recently adopted Consul and using Spring Cloud Consul. The YAML configs we brought over are using multi-doc in single YAML file, so we had to split out into individual files and it worked for us. Not so bad of a workaround all together but would be very interested if this enhancement would come in a future release of this Spring cloud module.

cabbonizio avatar Nov 11 '20 15:11 cabbonizio

We run into this issue but with a different effect. When adding a YML with two pages in Consul, the service started fine, but couldn't read any configuration entry.

Two documents YML was stored in KV as a single entry at: consul/kv/config/service-name/data

Since there weren't any errors, we tried to update the configuration values from the Consul UI to check if it was reading it from Consul for real and then noticed that the service left in the log an empty array for the refreshed keys "Refresh keys changed: []"

It all worked fine when we removed the second document in the YML from Consul. It was a bit hard to figure out this one...

jdeex avatar Jun 16 '21 16:06 jdeex

+1 on this

hsahota93 avatar Mar 29 '23 20:03 hsahota93

+1 on this

mpoxberry avatar Mar 29 '23 23:03 mpoxberry

+1 I have a use case where I have to store multiple YAML blobs in the consul server (under the same application and profile). I have to read them at the same time. Is it possible?

Hoyuelos avatar Apr 03 '23 14:04 Hoyuelos