bunny icon indicating copy to clipboard operation
bunny copied to clipboard

How to make message to DirectExchange auto-dropped if there is no queue listening that key

Open wangyuesong opened this issue 10 years ago • 1 comments

I have such a scenario that I am not sure if Bunny can support: I have a Producer that periodically produce messages. And there are 3 consumers. Because I want to mimic the RPC,so instead of using Fanout Exchange, every round my producer send three messages to DirectExchange with corresponding routing key. And consumer will get the message and reply to the temporary reply queue. So the question is, my Consumer is not always online(I was implementing RAFT consensus algorithm). But when it comes online previous "stale" messages sent by Producer just come through and my just-online consumer started to process so many RPC message that's already not valid, which break my application logic. Is there any way I can send a message to DirectExchange, and if there is not a queue listening to the routing key, the message just get dropped? I am considering make a Timestamp before sending and check timestamp when received, but this is clearly not a good solution since the "stale threshold" is hard to settle. Thank you so much guys! Any help is appreciated.

wangyuesong avatar Jun 02 '16 21:06 wangyuesong

Never mind. I figured it out. Here is my code @append_entries_direct_exchange.publish('Append Entries', :expiration => Misc::RPC_TIMEOUT, :routing_key => peer.append_entries_queue_name, :correlation_id => call_id, :reply_to=>reply_queue.name)

set expiration by millisecond. CAUTION, value should be a string, not a int.

wangyuesong avatar Jun 02 '16 23:06 wangyuesong