# Using proxy.destination\_service\_name to fetch rabbitmq service address for amqp port and create service for mqtt port

**URL:** <https://discuss.hashicorp.com/t/using-proxy-destination-service-name-to-fetch-rabbitmq-service-address-for-amqp-port-and-create-service-for-mqtt-port/28251>\
**Category:** Consul\
**Created:** [August 15, 2021, 3:45pm UTC](https://discuss.hashicorp.com/t/using-proxy-destination-service-name-to-fetch-rabbitmq-service-address-for-amqp-port-and-create-service-for-mqtt-port/28251 "2021-08-15T15:45:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morabaraba](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/morabaraba/32/21578_2.png) [@Morabaraba](https://discuss.hashicorp.com/u/Morabaraba)\
**Post date:** [August 15, 2021, 3:45pm UTC](https://discuss.hashicorp.com/t/using-proxy-destination-service-name-to-fetch-rabbitmq-service-address-for-amqp-port-and-create-service-for-mqtt-port/28251/1 "2021-08-15T15:45:34Z")

</div>

Hi

I’m using Consul to do [RabbitMQ Peer Discovery](https://www.rabbitmq.com/cluster-formation.html#peer-discovery-consul). It generates a service as follow:

```json
        "Service": {
            "ID": "rabbitmq:rabbitmq_rabbitmq-swarm-node-1",
            "Service": "rabbitmq",
            "Tags": [
                "amqp"
            ],
            "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:

```auto
;; ANSWER SECTION:
_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:

```auto
;; ANSWER SECTION:
_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(consul-mqtt.py)](https://gist.github.com/Morabaraba/e93a9f3e18e0d8916051ef119e48a00e) 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:

```json
{"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”](https://github.com/hashicorp/consul/issues/1202#issuecomment-298784543)  
but could not find any details behind this mechanism.

I tried the [`kind` field](https://www.consul.io/docs/discovery/services#connect) 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](https://www.consul.io/docs/discovery/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.

---

<div class="post-metadata">

**Author:** ![blake](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/blake/32/27620_2.png) [@blake](https://discuss.hashicorp.com/u/blake)\
**Post date:** [March 23, 2022, 4:41pm UTC](https://discuss.hashicorp.com/t/using-proxy-destination-service-name-to-fetch-rabbitmq-service-address-for-amqp-port-and-create-service-for-mqtt-port/28251/2 "2022-03-23T16:41:36Z")

</div>

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

[https://www.reddit.com/r/consul/comments/p5c302/for\_peer\_discovery\_using\_consul\_how\_to\_add\_mqtt/](https://www.reddit.com/r/consul/comments/p5c302/for_peer_discovery_using_consul_how_to_add_mqtt/)

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.
