How to stop rabbitmq server gracefully

3,252 views
Skip to first unread message

zhenbo zeng

unread,
Jan 16, 2017, 10:08:48 PM1/16/17
to rabbitmq-users
Hi
In my use case, every msg is so important, and I don't want to loss any msg.
I have to stop the rabbitmq server when upgrade the rabbitmq server or do something else.
Is there a way to stop the rabbitmq server gracefully?
For example, the rabbitmq server stop the producers and stop accepting new connections, wait consumers consume all the remain msgs, and then stop rabbitmq server itself.
Can these operations work on rabbitmq server, not the producer/consumer applications?

Michael Klishin

unread,
Jan 17, 2017, 2:47:24 AM1/17/17
to rabbitm...@googlegroups.com
System scripts, which will invoke `rabbitmqctl stop` which will use `rabbitmqctl stop_app` and then
also terminate the VM.

RabbitMQ will not wait for consumers, however, it will just shut down. Stopping or pausing individual apps
is up to you. You can set VM high memory watermark to something like 0.0000000001
to block all publishers but unless they *actually stop publishing attempts* that won't make
much difference.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

zhenbo zeng

unread,
Jan 17, 2017, 3:06:28 AM1/17/17
to rabbitmq-users
Thanks MK
Maybe I can write a script to do the follow step on the rabbitmq server :
1) stop the tcp listener
2) close the producer's connections
3) wait consumers consume the rest msgs
4) invoke `rabbitmqctl stop`

在 2017年1月17日星期二 UTC+8下午3:47:24,Michael Klishin写道:
System scripts, which will invoke `rabbitmqctl stop` which will use `rabbitmqctl stop_app` and then
also terminate the VM.

RabbitMQ will not wait for consumers, however, it will just shut down. Stopping or pausing individual apps
is up to you. You can set VM high memory watermark to something like 0.0000000001
to block all publishers but unless they *actually stop publishing attempts* that won't make
much difference.
On Tue, Jan 17, 2017 at 6:08 AM, zhenbo zeng <zhenb...@gmail.com> wrote:
Hi
In my use case, every msg is so important, and I don't want to loss any msg.
I have to stop the rabbitmq server when upgrade the rabbitmq server or do something else.
Is there a way to stop the rabbitmq server gracefully?
For example, the rabbitmq server stop the producers and stop accepting new connections, wait consumers consume all the remain msgs, and then stop rabbitmq server itself.
Can these operations work on rabbitmq server, not the producer/consumer applications?

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael Klishin

unread,
Jan 17, 2017, 3:10:52 AM1/17/17
to rabbitm...@googlegroups.com
If you have a good way to tell a publisher connection from a consumer one, it
sounds very doable, e.g. using HTTP API.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

komu wairagu

unread,
Jan 18, 2017, 8:12:56 AM1/18/17
to rabbitmq-users
I wonder if it's possible to manually invoke flow control: https://www.rabbitmq.com/flow-control.html 
If it is, then a graceful reload would consist of:
1. invoke flow control on the server (that way publishes are declined and so is consuming??)
2. have your client configured that it is always trying to establish/re-establish connection to the server
3. restart rabbitmq normally
4. client eventually re-establishes connection.

note: I'm just speculating, I don't know if that is possible.

R,
Komu W.

zhenbo zeng

unread,
Jan 19, 2017, 5:47:14 AM1/19/17
to rabbitmq-users
In my use case, publisher and consumer come from difference host, so I know a connection come from publisher or consumer

在 2017年1月17日星期二 UTC+8下午4:10:52,Michael Klishin写道:

zhenbo zeng

unread,
Jan 19, 2017, 5:56:47 AM1/19/17
to rabbitmq-users
flow control might not be able to stop publisher sending msgs to RMQ, just stop receiving msgs from OS kernel

在 2017年1月18日星期三 UTC+8下午9:12:56,komu wairagu写道:

Michael Klishin

unread,
Jan 19, 2017, 5:58:19 AM1/19/17
to rabbitm...@googlegroups.com
That is technically correct but TCP buffers are not infinite and at some point
write(2) (or similar) calls in your clients will block.

If you want to avoid that, it's an application coordination problem and RabbitMQ
is not a coordination server, even if to some extent it can be abused as such.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jdh...@gmail.com

unread,
Jan 15, 2019, 12:33:46 PM1/15/19
to rabbitmq-users
Did you guys ever figure this out?  We're having the same struggle on our system.  We'd like to turn off input to RabbitMQ, wait for the queues to empty, and then shutdown RabbitMQ.  Thank you in advance.

Michael Klishin

unread,
Jan 15, 2019, 3:09:28 PM1/15/19
to rabbitm...@googlegroups.com
This list uses one question per thread.

Those who want to shut down publishers can set the low VM memory watermark to 0 (or a very low fraction) to trigger
an alarm that will block publishers immediately.

Then you need to monitor consumers or make consumers voluntarily stop after a certain period of inactivity.

[1] can be draw some inspiration, too.

Reply all
Reply to author
Forward
0 new messages