Updated on 2024-04-01 GMT+08:00

Queue Migration

If queues are not evenly distributed across the nodes in a RabbitMQ cluster due to node scale-out or queue deletion, some nodes will be overloaded and the cluster cannot be effectively used.

To configure queue load balancing, use the following methods:

Deleting and Recreating Queues

  1. Log in to the RabbitMQ management UI.
  2. On the Overview tab page, click Download broker definitions to export the metadata.

  3. Stop producing messages, wait until all messages are consumed, and then delete the original queues.

    1. On the Overview tab page, check data consumption.

      If the number of messages that can be consumed (Ready) and the number of messages that are not acknowledged (Unacked) are both 0, the consumption is complete.

    2. When all data is consumed, delete the original queues.
      1. On the Queues tab page, click the name of the desired queue.

      2. Click Delete Queue to delete the queue.

  4. On the Overview tab page, upload the exported metadata.

    1. On the Overview tab page, click Choose File and select the exported metadata.
    2. Click Upload broker definitions to upload the metadata.

      If the upload is successful, the following information is displayed:

      The instance automatically creates queues across nodes for load balancing. You can view the queue distribution details on the Queues tab page.

Modifying the Master Node Using a Policy

  1. Log in to the RabbitMQ management UI.
  2. On the Admin > Policies page, add a policy.

    • Name: Enter a policy name.
    • Pattern: queue matching mode. Enter a queue name. Queues with the same prefix will be matched.
    • Apply to: Select Queues.
    • Priority: policy priority. A larger value indicates a higher priority. This parameter is optional.
    • Definition: mapping definitions. Set ha-mode to nodes and ha-params to the name of node to which the queues are to be migrated.

  3. Click Add policy.

    • Queue data synchronization takes a long time. To prevent message loss, the original master node is still available before queue data synchronization is complete.
    • After the queue switchover is complete, you can delete the policy added in 2.