3
  • There are three nodes in a RabbitMQ cluster as below.
  • Within RabbitMQ, there are two queues, q1 and q2.
  • The master replica of q1 and q2 are distributed on different nodes. Both queues are mirrored by other nodes.
  • There is a load balancer in front of three nodes.
  • AMQP(node port 5672) and Management HTTP API(node port 15672) are exposed by load balancer.

enter image description here

When application establishes a connection through load balancer, it could reach a random RabbitMQ node behind. And this is invisible to application.

Question:

  1. Is it ok for application to consume both queues in a single AMQP channel over a single connection no matter which RabbitMQ node it reaches?

  2. It is ok for application to call management HTTP API no matter which RabbitMQ node its request hits?

Mr.Wang from Next Door
  • 13,670
  • 12
  • 64
  • 97
  • 1
    1. Yes. In general practice same channel is used to consume from multiple queues. What exactly do you mean by "which RabbitMQ node it reaches?" 2. Yes. The management information is kept in mnesia inside each node so the request to any node will suffice – Lalit Mehra Aug 02 '19 at 05:06
  • https://stackoverflow.com/questions/18418936/rabbitmq-and-relationship-between-channel-and-connection -> check this out for more clarity – Lalit Mehra Aug 02 '19 at 05:18

1 Answers1

4

When RabbitMQ is set up as a cluster and you have your queues mirrored across them, it doesn't matter to which node you are connected. Because the AMQP connection for a queue will be automatically routed to the node containing the master queue and this handled by RabbitMQ internally. So, if a request to publish or consume on queue q1 comes, it will be routed to Node #1.

Answers to your question.

  1. It is not advisable to consume more than one queues in a single AMQP connection. Exception from one consuming process may cause the connection to close which will interrupt the other one.

  2. It is ok for application to call management HTTP API no matter which RabbutMQ node its request hits. Once management plugin in a RabbitMQ cluster is enabled, all the nodes will accept the Management HTTP API requests.

Reference: https://www.rabbitmq.com/clustering.html

bumblebee
  • 1,811
  • 12
  • 19
  • Thanks @bumblebee, I may not make myself clear :) So application establishes a single connection to cluster. Over this connection, application creates only one channel. It is ok to consume both queues via this single channel, right? P.S. I am using RabbitMQ .NET Client. – Mr.Wang from Next Door Aug 02 '19 at 05:18
  • 2
    A connection can have multiple channels which might be used by multiple queues to connect to the broker. With each queue using its own connection there will be multiple TCP connections required which is not good for any system. – Lalit Mehra Aug 02 '19 at 05:20