Updated on 2024-09-18 GMT+08:00

Migrating RabbitMQ Services

There are two scenarios for migrating RabbitMQ services:

  • Single-node or cluster RabbitMQ instances can be migrated from on-premises to on-cloud RabbitMQ instances.
  • An earlier RabbitMQ instance can be migrated to a later one, for example, from 3.7.17 to 3.8.35.

Migration Principle

A RabbitMQ instance has multiple producers and consumers. To migrate services, add and remove them one by one without altering data. This process has no impact on services.

Prerequisite

A target RabbitMQ instance has been created. For details, see Buying a RabbitMQ Instance.

Implementation (Dual-Read)

  1. Migrate source RabbitMQ instance metadata to a target RabbitMQ instance.

    Figure 1 Migrating metadata

    Do as follows:

    1. Log in to the management UI of the source RabbitMQ. On the Overview tab page, click Download broker definitions to export the metadata.
      Figure 2 Exporting metadata
    2. Log in to the management UI of the target RabbitMQ. On the Overview tab page, click Choose File and select the metadata exported in 1.a, and click Upload broker definitions to upload the metadata.
      Figure 3 Importing metadata

  2. Add new consumers for the target RabbitMQ instance.

    Figure 4 Adding new consumers

  3. Add new producers for the target RabbitMQ instance and remove the producers of the source RabbitMQ instance. The old consumers continue consuming messages from the source RabbitMQ instance.

    Figure 5 Migrating producers

  4. After the old consumers have consumed all messages from the source RabbitMQ instance, remove them along with the source RabbitMQ instance.

    Figure 6 Removing an old consumer and a source RabbitMQ instance

Check After Migration

Check whether the consumption from the source instance is complete in either of the following ways:

  • Using the RabbitMQ management UI, as shown in Figure 7.

    On the Overview tab page, 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.

    Figure 7 RabbitMQ management UI
  • Calling an API
    curl -s -u username:password -XGET http://ip:port/api/overview

    Parameter description:

    • username: account of the source instance to log in to the RabbitMQ management UI
    • password: password of the source instance to log in to the RabbitMQ management UI
    • ip: IP address of the source instance to log in to the RabbitMQ management UI
    • port: port of the source instance to log in to the RabbitMQ management UI

    The consumption is complete when messages_ready and messages_unacknowledged values in the command output are both 0.

    Figure 8 Command output