简体   繁体   中英

How to “buffer” messages if no queues yet bound to an exchange in RabbitMQ?

Im very new to RabbitMQ so this might be something that Im simply missing. My "problem" is that I have this application that will send "events" over RabbitMQ using pub/sub and an exchange. However, there might or might not be any consumers yet of these events, but once there is one, I would like that consumer to get any events/messages that has happened before it connected. So basically I would like the exchange to "buffer" all the messages, and as soon as there is one queue bound to the exchange (queue created and bound by the consumer) the exchange should push all buffered messages to that queue for the consumer to then.. well.. consume.

I have read about "alternate exchange" which doesnt really seam to do what Im describing, from my understanding is that all that does is forward all messages from the original exchange to the alternate exchange, and then the alternate exchange would publish messages to its queues to be consumed by the consumers (so not much "buffering").

Is my goal possible to achieve by simply configuring RabbitMQ? Or is there any other "documented" pattern to achieve my goal?

In order to "buffer" messages, you must have a queue declared and routed from the exchange.

It doesn't matter if you have a consumer or not, you can define the queue as auto-delete=false which will keep it, even if no consumer is connected.

and you can set it also as durable=true so it will survive a broker restart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM