I’ve set up a headers exchange in RabbitMQ with an alternate exchange (of type fanout). Partly I just want to see how this works, but partly I think this is a bit more flexible than a dead-letter exchange/queue (for example, if I want to have multiple queues in the alternate-exchange with different producers so the same message can be handled in different ways).
The setup is like this:
{:ok, connection} = AMQP.Connection.open([]),
{:ok, channel} = AMQP.Channel.open(connection)
:ok = AMQP.Exchange.declare(channel, "fallback_exchange", :fanout, durable: true),
:ok = AMQP.Exchange.declare(channel, "headers_exchange", :headers, durable: true, arguments: [{"alternate-exchange", :longstr, "fallback_exchange"}])
# The regular queue(s)...
AMQP.Queue.declare(channel, "q1", durable: true)
AMQP.Queue.bind(channel, "q1", "headers_exchange", arguments: [{"h1", :longstr, "abc"}, {"x-match", :longstr, "all"}])
# ... etc...
# The dead-letter queue(s)...
AMQP.Queue.declare(channel, "misfits", durable: true)
AMQP.Queue.bind(channel, "misfits", "fallback_exchange")
I have a Broadway producer bound to "q1"
, and it is handling regular messages fine. But when it fails a message, that message is not sent onward to the "fallback_exchange"
… it just seems to be acked and discarded.
I can see that the "misfits"
queue receives messages when a message is published to the headers exchange but there were no matching bindings.
Do I have to manually publish messages back to the "fallback_exchange"
in the handle_failed/2
callback? I think this will work, but I would prefer that the Broadway producer not know or care about that stuff. Is this possible? Did I configure this incorrectly?
Thanks for any guidance!