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

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

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
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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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

We're in Beta

About us Mission Statement