Skip to main content
Version: 54.0.0

Using Services in Apps

This topic provides usage guidance for binding all a9s Data Services to Cloud Foundry apps.

Binding Information

Binding information is delivered to apps via the VCAP_SERVICES environment variable. This variable is a JSON object string.

Structure

  • hash of services (e.g a9s-redis7, a9s-postgresql11...)
    • array of service instances
      • name
        • string
      • tags
        • array of tag as strings
      • credentials
        • service specific credentials

Environment Variable Example

VCAP_SERVICES:

{
"a9s-rabbitmq310": [
{
"name": "example-rabbitdb",
"tags": [ "rabbitmq" ],
"credentials": {
"host": "localhost",
"password": "quest",
"port": 5672,
"uri": "amqp://guest:guest@localhost:5672",
"username": "guest"
}
}
]
}

Best Practices

  1. Do not rely on order in VCAP_SERVICES
  2. Do not rely on service versions
  3. Do not hard code service instance names

Suggested Practices

Option A

Specify the service name via an environment viable with your app manifest. This is trivial to implement in an app, and follows the best practices making it easy to rebind an apps without changing code in your app.

Option B

Look for a service instance with a tag, that can be hard coded in an app, without compromising the best practices. This is trivial to implement, but you must clearly document the tag you have hard coded. The advantage of this option is not having to update a variable in an app manifest when rebinding.

RabbitMQ Go Example

Here you can find a RabbitMQ example of how to simultaneously implement suggested practices A and B in an app.