pivotal-cf / java-cfenv

Apache License 2.0
95 stars 59 forks source link

Need to bind multiple rabbitmq and/or mysql services to JVM #87

Closed MrMarkW closed 4 years ago

MrMarkW commented 4 years ago

I'm in PCF using SCS 3.1 with the following dependencies:

CfEnvironmentPostProcessor doesn't allow multiple Rabbitmq service instances to be bound to a single application.

I'm looking for a way to override or disable CfEnvironmentPostProcessor for our rabbitmq and mysql bindings since we need to support multiple rabbitmq clusters and mysql instances in a single JVM. I would be fine adding my own custom PostProcessor to handle these situations, but I haven't seen a clear example of how to override or disable what is set in the META-INF/spring.factories

Is the better option to use try spring-cloud/spring-cloud-connectors 2.x instead? We are new to the PCF and would prefer to build upon the new models.

Any help would be much appreciated!

dyroberts commented 4 years ago

Hi @maximusfloydus. As a workaround, I would suggest excluding the io.pivotal.cfenv:java-cfenv-boot dependency and adding a dependency on the more flexible base library io.pivotal.cfenv:java-cfenv-jdbc. Once this is done, you can follow the docs here to connect as many services as you need of each type. If you go this route, you'll also need to configure the scs properties in this manner as well. You can find them here for config-client and here for eureka-client.

dyroberts commented 4 years ago

The other option is, as you mentioned, to use the 2.x line of scs starters. But, as you've noticed, they use spring-cloud-connectors; which I don't believe will reduce the complexity for you.

MrMarkW commented 4 years ago

By excluding io.pivotal.cfenv:java-cfenv-boot I lose access to two import classes: io.pivotal.cfenv.spring.boot.CfEnvProcessor and `io.pivotal.cfenv.spring.boot.CfEnvProcessorProperties...

dyroberts commented 4 years ago

The CfEnvProcessor is the main abstraction of the boot module. Since you're not going to use the boot module, you won't be writing any CfEnvProcessors! You'll just follow the docs here to set application properties with SpEL and the CfJdbcEnv bean. See my comment above for details on the particular properties that need setting for scs.

dyroberts commented 4 years ago

After some thought, I think the approach suggested above is the best one for supporting multiple services of the same type.

MrMarkW commented 4 years ago

@dyroberts Can SpEL be used in Spring Cloud Configuration or only in a local properties file?

It would be ideal if pivotal/vmware provide a little more flexibility in this library. I really would like to use this library for SCS Config, SCS registry, SSO and maybe a few other things. I just can't use it for JDBC or AMPQ in my current applications. I saw a PR to support a "enabled" flag #40. Another option would be allow the PostProcessor to not exit when it finds multiple, but just log the error and process the rest. I could do a PR also, if there is a path you guys would be willing to accept.

dyroberts commented 4 years ago

Thanks for your persistence @maximusfloydus. I've merged the Is enabled PR and released java-cfenv v2.1.2.RELEASE.