As already mentioned, if you simply mark messages as permanent, they will not necessarily be saved immediately, therefore, if the server shuts down unexpectedly, they may never end up on disk.
So what do you do if you really need the message to be on disk, even if the server crashes?
There are two things you can do. One of them is to wrap the publication in a transaction. When you have completed the transaction, the message will be on disk (if it has not already been delivered to the end user). However, this adds a synchronous call to the server, so it can slow down. If you know that you are going to publish many messages, you can wrap a bunch of publications in a transaction, and then when you commit that you know that they are all on disk.
Another (better performance) alternative is to use publication confirmations. But they are new on server 2.3.1, and I do not think that all Ruby clients support them.
Finally, RabbitMQ will in any case periodically erase persistent messages to disk even in the absence of confirmations, transactions and controlled stops. However, there is an error in 2.2.0, which means that this sometimes does not happen for a long time, so updating to 2.3.1 may be useful.
source share