Using proxy.destination_service_name to fetch rabbitmq service address for amqp port and create service for mqtt port


I’m using Consul to do RabbitMQ Peer Discovery. It generates a service as follow:

        "Service": {
            "ID": "rabbitmq:rabbitmq_rabbitmq-swarm-node-1",
            "Service": "rabbitmq",
            "Tags": [
            "Address": "rabbitmq_rabbitmq-swarm-node-1",
            "Meta": null,
            "Port": 5672,
            "Weights": {
                "Passing": 1,
                "Warning": 1
            "EnableTagOverride": false,
            "Proxy": {
                "Mode": "",
                "MeshGateway": {},
                "Expose": {}
            "Connect": {},
            "CreateIndex": 15,
            "ModifyIndex": 15

The above allows me to ask the Consul DNS Server for the SRV Record which returns as follow:

_rabbitmq._amqp.service.consul. 0 IN    SRV     1 1 5672 rabbitmq_rabbitmq-swarm-node-1.

But I would also like to ask for a second SRV Record returning the mqtt/ssl port, eg:

_rabbitmq._mqtt_ssl.service.consul. 0 IN SRV    1 1 8883 rabbitmq_rabbitmq-swarm-node-1.

I created the above SRV Record with a rudimentary python script( that uses the Consul http api /v1/health/service/rabbitmq
to filter by "amqp" in Service.Tags and register similar services using /v1/agent/service/register but with the mqtt_ssl
tag and different port, as follow:

{"Name": "rabbitmq", "Tags": ["mqtt_ssl"], "Port": 8883, "ID": "rabbitmq:rabbitmq_rabbitmq-swarm-node-1-mqtt", "Address": "rabbitmq_rabbitmq-swarm-node-1"}

While this works, I feel there should be a simpler solution.

I found on github issues that “service tags provide a working mechanism”
but could not find any details behind this mechanism.

I tried the kind field and set proxy.destination_service_name = rabbitmq with the port = 8883 but realised I need to still setup a address.

And explored DNS Prepared Query Lookups in a attempt to see if I can craft a query to change the port, but it seems the only DNS option one can change is ttl.

So any guidance or nudge in the right direction to rather use a native Consul feature instead of my script hack would be really appreciated.

This question was also asked on the Consul sub-reddit.

I realized that I replied there, but did not reply on this post. Sharing my comment here for visibility.

Consul currently only allows associating a single port with a service. As such, it is not possible to register a service that has two different ports (even if one is accessible over a different tag).

The only workaround for this is exactly what you’re doing, which is register an entirely new service instance that references a different port number.