TLDR: how 2+ instances of the same task can communicate between each other while using connect?
I was wondering … is it possible to somehow deploy multiple instances of RabbitMQ talking to each other using consul connect?
I’ve found some examples without using connect with some advanced magic I’m not yet familiar with.
I’ve managed to run 2 separate instances using connect - that’s easy.
But I did not manage to connect them to each other so they would form a cluster.
So the questions I have:
Do you know and can tell how to do this thing? (or point me to some already existing resource)
Do you know something with a similar problem? (elasticsearch comes to mind)
What are some keywords I might be looking for? (apparently “consul connect” “nomad” “rabbitmq” isn’t it)
Edit:
From what I’ve read there’s no access to Consul from the container itself so there’s no point in trying to use rabbitmq_peer_discovery_consul
. In bridge mode anyway.
I could use a template to use the cluster_formation.peer_discovery_backend = classic_config
and generate the config, but I’m not sure if it can handle IPs instead of hostnames. I’d also have to have a separate upstreams section for each instance so the ports don’t clash. And those different ports might also be an issue for the rabbit.
What I have now:
job "rabbitmq" {
datacenters = ["dc1"]
type = "service"
group "rabbitmq" {
count = 2
network {
mode = "bridge"
}
service {
name = "rabbitmq"
port = "5672"
connect {
sidecar_service {
proxy {
# this is currently useless
upstreams {
destination_name = "consul"
local_bind_port = "5200"
}
}
}
}
}
service {
name = "rabbitmq-management"
tags = ["management"]
port = "15672"
connect {
sidecar_service {}
}
}
task "rabbitmq" {
resources {
cpu = 1000
memory = 1000
}
template {
data =<<EOH
[rabbitmq_management,rabbitmq_peer_discovery_consul].
EOH
destination = "local/enabled_plugins"
}
template {
data =<<EOH
cluster_formation.peer_discovery_backend = consul
# next 2 lines doesn't work since it can't resolve it
cluster_formation.consul.host = {{ env "NOMAD_UPSTREAM_IP_consul" }}
cluster_formation.consul.port = {{ env "NOMAD_UPSTREAM_PORT_consul" }}
cluster_formation.consul.svc = rabbitmq-cluster
cluster_formation.consul.acl_token = xxx # I'm testing now, it's fine :)
EOH
destination = "local/rabbitmq.conf"
}
driver = "docker"
config {
image = "rabbitmq:3.8-management-alpine"
volumes = ["local/enabled_plugins:/etc/rabbitmq/enabled_plugins", "local/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf"]
}
}
}
group "rabbitmq-management-ingress" {
network {
mode = "bridge"
port "inbound" {
static = 15672
to = 15672
}
}
service {
name = "rabbitmq-management-ingress"
port = "15672"
connect {
gateway {
proxy {}
ingress {
listener {
port = 15672
protocol = "tcp"
service {
name = "rabbitmq-management"
}
}
}
}
}
}
}
}