Blue/Green deployment with Consul

Hello,

I have RabbitMQ 3.7 running and it is registered on Consul as rabbitmq-37 and now I want to do upgrade to version 3.8 so I set another cluster as rabbitmq-38. Is it possible to create an alias for a service, like rabbitmq, that will point to one of two services, so that I can always use the same service name in my applications?
I did have some limited success with registration of “external” service like this:

{
  "Datacenter": "test",
  "Address": "rabbitmq-37.service.consul",
  "Node": "aliasnode",
  "Service": {
    "Service": "rabbitmq"
  }
}

but the problem with this is that ports are not resolved properly for SRV records.
Is there some other way? Maybe I am doing it all wrong. :slight_smile:

Thanks,
Damir

Hi @damirda,

The easiest way to achieve this without changing how you currently register services would be to create a prepared query which serves as an alias to the correct service.

For example, create file called payload.json.

{
  "Name": "rabbitmq",
  "Service": {
    "Service": "rabbitmq-37"
  }
}

Then create the query using curl.

$ curl \
    --request POST \
    --data @payload.json \
    $CONSUL_HTTP_ADDR/v1/query

Clients can then query the address rabbitmq.query.consul, and the address(es) of the rabbitmq-37 service will be returned. This works for all supported query types (A/AAAA, SRV, TXT).

$ dig rabbitmq.query.consul +short
10.42.1.75
$ dig -t SRV rabbitmq.query.consul +short
1 1 8080 0a2a014b.addr.dc2.consul.
$ dig 0a2a014b.addr.dc2.consul +short    
10.42.1.75

You then just need to update the query to point to the new service name (e.g., rabbitmq-38) when you want to migrate to a different version.

1 Like

Hello @blake,

Thank you for your answer. In the meantime I found the same solution as well. :wink: