basvanwesting

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:

  1. ACK to the original queue
  2. 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

benonymus

This is probably very late, but you need to nack the message not ack

Also Liked

basvanwesting

basvanwesting

Thanks! Better late than never :slight_smile:

So simple NACK-ing the message triggers the dead-letter queue routing. Seems quite obvious in hindsight… I try it out!

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement