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

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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
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
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
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
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

We're in Beta

About us Mission Statement