basvanwesting
Broadway RabbitMQ redirect to dead-letter queue example requested
Hi,
I’m using BroadwayRabbitMQ.Producer to read from a RabbitMQ queue and handle the messages. However, I’m having trouble redirecting to a dead-letter queue for failed messages. In the docs it is mentioned several times, but never implemented in an example. And I simply can’t find any example on the internet as well.
I can flag the message as failed in handle_message/3 with Broadway.Message.failed/2. The message then ends up in handle_failed/2, where I want to redirect it to the dead-letter exchange/queue. There are two steps as far as I understand:
- ACK to the original queue
- Send to the dead-letter queue/exchange
I would expect to be able to reuse the existing connection to RabbitMQ to redirect to the dead-letter queue/exchange somehow.
The queues are setup as follows:
with {:ok, queue_base} = Application.fetch_env(:amqp, :some_named_queue),
{:ok, connection_options} = Application.fetch_env(:amqp, :connection_options),
{:ok, conn} <- Connection.open(connection_options),
{:ok, chan} <- Channel.open(conn),
{:ok, _} <- Queue.declare(chan, "#{queue_base}_error", durable: true),
# Messages that cannot be delivered to any consumer in the main queue will be routed to the error queue
{:ok, _} <- Queue.declare(chan, queue_base,
durable: true,
arguments: [
{"x-dead-letter-exchange", :longstr, ""},
{"x-dead-letter-routing-key", :longstr, "#{queue_base}_error"}
]
),
:ok <- Exchange.fanout(chan, "#{queue_base}_exchange", durable: true),
:ok <- Queue.bind(chan, queue_base, "#{queue_base}_exchange") do
:ok
end
Thanks, Bas
Marked As Solved
benonymus
This is probably very late, but you need to nack the message not ack
Also Liked
basvanwesting
Thanks! Better late than never ![]()
So simple NACK-ing the message triggers the dead-letter queue routing. Seems quite obvious in hindsight… I try it out!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








