问题
I've been using cloud foundry for the past 2-3 months and have come across user defined and managed services. My understanding was that in case of managed services come along with the required implementing if service broker and in case of user defined services , the one who is defining the service has to take care of the implementation. I wanted to understand what is the advantage of using managed / user defined service over defining the connection details within the application ( or externalizing it in property files )
回答1:
I believe the overall advantage of using the service binding approach is that the application does not have to have multiple configuration files for each possible environment it will be deployed to.
Specifically, if you have Dev, Test, Stage and Prod environments, you'll probably have a collection of configurations that reflect the custom URL/IP/Ports/credentials of each environment. You'll also need some way to trigger the use of the correct environment configuration. In the Spring Boot approach, you typically use Spring Profiles to define and activate these configurations. However, this typically implies that your application is bundled with all required profile configuration ahead of time.
With Cloud Foundry, the connection/service binding details are injected from via the deployed cloud platform itself. Which means that you only really need one "cloud" profile defined that will work for all the environments you have to support.
This approach can be argued to have a few benefits:
You can stand up new environments and not have to rebuild/reconfigure the application itself. For example, if you have a short-term need for a Test2, you can easily create and define a new space and service binding(s) without having to rebuild the app. Technically, you can achieve this other ways -- as you suggest by externalizing the configuration. My understanding of CF is that this isn't really an encouraged practice (and may not be easily achieved unless you externalize everything as independent environment variables).
You don't have to have credentials stored within the application configuration. This can be argued to be a security benefit in that application developers never have to know connection details to any services they bind to outside their local environments. This may or may not be important to you.
You might be able to use different implementations of backing services across environments (possibly to avoid high licensing costs in non-prod?). I'm not a fan of this approach, so I don't really see it as a benefit.
Hopefully others with more exposure to Cloud Foundry can chime in if there are other potential benefits that I'm missing.
Also, I would look at this project: http://cloud.spring.io/spring-cloud-connectors/ more closely to see if you can gain any additional benefits with the approach.
来源:https://stackoverflow.com/questions/34759332/pivotal-cloud-foundry-managed-vs-user-defined-service