spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

Document howto share common properties for a subset of services #618

Open rmotapar opened 7 years ago

rmotapar commented 7 years ago

We have several micro-services in our project that use the same config server (same git repository). Any common properties that are needed by more than one service/module are being placed in application.properties. So if serviceA and serviceB need a property, it will be placed in application.properties. But the problem is that this property will be available to rest of the services as well. This makes it harder for the dev ops team to configure the application.properties as they need to understand which specific properties apply to a particular service. For better manageability, we would also like to store these properties in separate files and have services load them up via config server.

So my questions are: Is there any way we can share a common set of properties among a subset of services (and not all of them) without polluting the base application.properties? Is it possible to define multiple base files for a service? For example,

I would like to have multiple base property files like below: application.properties application-prod.properties cassandra.properties cassandra-prod.properties jpa.properties jpa-prod.properties redis.properties redis-prod.properties async.properties async-prod.properties

And configure a service to use just the property files that it needs. So serviceA and serviceB which use cassandra can be configured to use application.properties and cassandra.properties whereas ServiceC which needs jpa will be configured to use application.properties and jpa.properties

Please let me know if something like above is possible and if there are any approaches that might help in our case. Thanks in advance for any help/suggestions you can provide

spencergibb commented 7 years ago

Use profiles? At the very least application-cassandraprod.properties. I'm checking with the boot team to see if you can qualify with multiple profiles.

We use the boot mechanisms to load these files, so we don't want to stray from that.

spencergibb commented 7 years ago

The only special file in configserver is application.{yml|properties}, everything else is based off the application name passed in.

spencergibb commented 7 years ago

You could set, on the client side, spring.cloud.config.name=${spring.application.name},cassandra, and the profile prod, then it would pick up (if spring.application.name=foo): foo.properties, foo-prod.properties, cassandra.properties and cassandra-prod.properties.

That looks like it will work.

rmotapar commented 7 years ago

That's very good to know. I will test this and confirm the results soon. Thank you @spencergibb

spencergibb commented 7 years ago

Might be nice to add to the docs.

rmotapar commented 7 years ago

@spencergibb It is working as you described. Thank you very much! One thing I noticed is that the order of the names defined under spring.cloud.config.name matters. That is, if spring.application.name=cassandra,servicea then properties in servicea.properties file override any matching properties in cassandra.properties

spencergibb commented 7 years ago

Noted on ordering. That is because that is how the properties are ordered coming back from config server, so it does make sense to me.