Search code examples
javaspringrabbitmqmigrationspring-rabbit

Is there a way to do "migration" on RabbitMQ queues, exchanges, bindings, etc?


I would like to know if there is any alternative to create / change / remove exchanges, queues and bindings without depending of the framework (in my case, Spring) for this and his limitations.

The problem

Often I need to change the name of a Routing Key, Queue, or Exchange, and these frameworks do not allow to do this "refined" changes. As a consequence, the tendency is continue with the original names of queues/keys and even the original setup (durable, DLQ, etc). On the future, this ends up confusing the organization of the queues, because you can not easily give proper maintenance to their name, configuration, eventually reorganize them at different exchanges, etc.

Actually, the only way to accomplish that is manually removing them from each environment and let the framework recreate them. Or moving the messages for a temporary queue to do the same.

I would like to know if there are any alternative to control this, something like the tools for database migration, like Liquibase, Flyway, etc.

Making a parallel situation with the database problem, currently letting the Spring create everything in RabbitMQ seems to me analogous to leaving hbm2ddl Hibernate option on update on a Production database.


Solution

  • You can change some things but not others - but you have to do it programmatically, not declaratively.

    You can use RabbitAdmin.declareBinding() to bind a queue with a different routing key (and/or exchange), and then use removeBinding() to remove the old one.

    You cannot change queue arguments (DLQ settings etc) or durability.

    You can use the shovel plugin to move messages from an old queue to a new one.