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
https://www.rabbitmq.com/dlx.html

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

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
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
Tee
can someone please explain to me how Enum.reduce works with maps
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement