Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

rabbit credentials might be incomplete / miss virtualhost info

Open
#52 5 comments 0 reactions 1 assignee View on GitHub

@markpollack is already working on this.

Since May 31, 2019.

Assessment

This issue has not been assessed yet.

Description

enhancement

We deploy or applications on two different CF installations (pivotal and swisscom). The two are different in terms of how the rabbit credentials are defined in VCAP_SERVICES.

The rabbit credentials on pivotal only provide uri and http_api_uri in the credentials, where swisscom also provides things like the very important virtualhost (vhost). Although the virtual host ist also part of the uri on pivotal (last part of the uri), it is quite cumbersome to get hold of it. As a workaround we currently take advantage of the fact that virtualhost is equals to the username when the service is provided by cloudamqp on pivotal.

So our current config looks like this (we fallback to the username in case there is no vhost defined):

@Bean
public ConnectionFactory rabbit(CfEnv cfEnv) {
	// "label" must match name of bound service on CF!
	CfCredentials rabbitCredentials = cfEnv.findCredentialsByName("rabbit");
	CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitCredentials.getHost(), Integer.parseInt(rabbitCredentials.getPort()));
	connectionFactory.setChannelCacheSize(CHANNEL_CACHE_SIZE);
	connectionFactory.setUsername(rabbitCredentials.getUsername());
	connectionFactory.setPassword(rabbitCredentials.getPassword());

	String vhost = StringUtils.isNotBlank(rabbitCredentials.getString("vhost")) ? rabbitCredentials.getString("vhost") : rabbitCredentials.getUsername();
	connectionFactory.setVirtualHost(vhost);

	return connectionFactory;
}

With this issue, I ask you to provide a more reliable way to access the virtualhost also in case where it is only configured in the uri (as in the case on run.pivotal.io). If not possible, I suggest to add some kind of documentation about this.
...btw, this did not make any difference with the old cloud connector api - everything was picked up automatically and was working fine.

VCAP_SERVICES details:
on run.pivotal.io, service provided by cloudamqp:

...
"cloudamqp": [
        {
          "label": "cloudamqp",
          "provider": null,
          "plan": "tiger",
          "name": "rabbit",
          "tags": [
            "amqp",
            "rabbitmq"
          ],
          "instance_name": "rabbit",
          "binding_name": null,
          "credentials": {
            "uri": "amqp://xxxxx:[email protected]/xxxxx",
            "http_api_uri": "https://xxxxx:[email protected]/api/"
          },
          "syslog_drain_url": null,
          "volume_mounts": []
        }
      ]
    }
...

swisscom, service provided by swisscom:

    "rabbitmqent": [
      {
        "label": "rabbitmqent",
        "provider": null,
        "plan": "usage",
        "name": "rabbit",
        "tags": [
          "rabbitmq"
        ],
        "instance_name": "rabbit",
        "binding_name": null,
        "credentials": {
          "uri": "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
          "uris": [
            "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
            "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
            "amqp://xxxxx:[email protected]/vvvvvvvvvvvv"
          ],
          "vhost": "vvvvvvvvvvvv",
          "username": "xxxxx",
          "password": "pppppppppp",
          "hostname": "rabbitmq.service.consul",
          "hostnames": [
            "node-0.service.consul",
            "node-1.service.consul",
            "node-2.service.consul"
          ],
          "port": 5672,
          "amqp_port": 5672,
          "mqtt_port": 1883,
          "stomp_port": 61613,
          "management_port": 15672,
          "http_api_uri": "http://xxxxx:[email protected]:15672/api",
          "http_api_uris": [
            "http://xxxxx:[email protected]:15672/api",
            "http://xxxxx:[email protected]:15672/api",
            "http://xxxxx:[email protected]:15672/api"
          ],
          "protocols": {
            "amqp": {
              "username": "xxxxx",
              "password": "pppppppppp",
              "port": 5672,
              "host": "rabbitmq.service.consul",
              "hosts": [
                "node-0.service.consul",
                "node-1.service.consul",
                "node-2.service.consul"
              ],
              "uri": "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
              "uris": [
                "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
                "amqp://xxxxx:[email protected]/vvvvvvvvvvvv",
                "amqp://xxxxx:[email protected]/vvvvvvvvvvvv"
              ],
              "vhost": "vvvvvvvvvvvv"
            },
            "http": {
              "username": "xxxxx",
              "password": "pppppppppp",
              "port": 15672,
              "host": "rabbitmq.service.consul",
              "hosts": [
                "node-0.service.consul",
                "node-1.service.consul",
                "node-2.service.consul"
              ],
              "uri": "http://xxxxx:[email protected]/vvvvvvvvvvvv",
              "uris": [
                "http://xxxxx:[email protected]/vvvvvvvvvvvv",
                "http://xxxxx:[email protected]/vvvvvvvvvvvv",
                "http://xxxxx:[email protected]/vvvvvvvvvvvv"
              ],
              "vhost": "vvvvvvvvvvvv"
            },
            "mqtt": {
              "username": "vvvvvvvvvvvv:xxxxx",
              "password": "pppppppppp",
              "port": 1883,
              "host": "rabbitmq.service.consul",
              "hosts": [
                "node-0.service.consul",
                "node-1.service.consul",
                "node-2.service.consul"
              ],
              "uri": "mqtt://vvvvvvvvvvvv%3Axxxxx:[email protected]",
              "uris": [
                "mqtt://vvvvvvvvvvvv%3Axxxxx:[email protected]",
                "mqtt://vvvvvvvvvvvv%3Axxxxx:[email protected]",
                "mqtt://vvvvvvvvvvvv%3Axxxxx:[email protected]"
              ]
            },
            "stomp": {
              "username": "xxxxx",
              "password": "pppppppppp",
              "port": 61613,
              "host": "rabbitmq.service.consul",
              "hosts": [
                "node-0.service.consul",
                "node-1.service.consul",
                "node-2.service.consul"
              ],
              "uri": "stomp://xxxxx:[email protected]",
              "uris": [
                "stomp://xxxxx:[email protected]",
                "stomp://xxxxx:[email protected]",
                "stomp://xxxxx:[email protected]"
              ],
              "vhost": "vvvvvvvvvvvv"
            },
            "management": {
              "uri": "http://xxxxx:[email protected]:15672/api",
              "uris": [
                "http://xxxxx:[email protected]:15672/api",
                "http://xxxxx:[email protected]:15672/api",
                "http://xxxxx:[email protected]:15672/api"
              ],
              "username": "xxxxx",
              "password": "pppppppppp",
              "host": "rabbitmq.service.consul",
              "hosts": [
                "node-0.service.consul",
                "node-1.service.consul",
                "node-2.service.consul"
              ],
              "port": 15672,
              "path": "/api",
            }
          }
Dominant language
Java
Stars
97
Forks
64
Avg merge
10h 45m
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pivotal-cf/java-cfenv

All issues in pivotal-cf/java-cfenv

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.