I am using RabbitMQ in a project and am running my integration tests against it. Since the tests need to be independent from each other, I would like to reset the RabbitMQ instance before each test and currently solve this by restarting the (automatically created) RabbitMQ docker container. However, this is extremely slow (for integration tests).
I know from this answer that it's possible to reset the rabbitmq-instance with rabbitmqctl stop && rabbitmqctl reset && rabbitmqctl start - but in case of the docker-image, the stop-signal kills the main container process (which is rabbitmq-server), which in turn leads to dockerd killing the complete container.
The only solution I found so far is running the management-api-plugin, iterating over all queues, exchanges, policies, etc. and deleting them through that - which in turn takes a while as well and requires the management-plugin to run.
Is it possible to reset a running rabbitmq-node programmatically via AMQP, some other API-endpoint or running a command, without stopping it first?
The answer you're referring to is correct in that you should be using stop_app, not stop like in your message.
There's an important difference between the two:
stop:
...stops RabbitMQ and its runtime (Erlang VM)
stop_app:
...stops the RabbitMQ application, leaving the runtime (Erlang VM) running
Because in rabbitmq container process containing Erlang VM is PID = 1, stopping it will obviously cause container to stop. Luckly, rabbitmq authors added stop_app command specifically to improve user experience related to testing.
The code from the answer you're referring to should work just fine. Here's the same code as a one-liner:
docker exec my_queue sh -c "rabbitmqctl stop_app; rabbitmqctl reset; rabbitmqctl start_app"
The output will look like this:
$ docker exec my_queue sh -c "rabbitmqctl stop_app; rabbitmqctl reset; rabbitmqctl start_app"
Stopping rabbit application on node rabbit@40420e95dcee
Resetting node rabbit@40420e95dcee
Starting node rabbit@40420e95dcee
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With