fireproofsocks

fireproofsocks

I’ve set up a headers exchange in RabbitMQ with an alternate exchange (of type fanout). Partly I just want to see how this works, but partly I think this is a bit more flexible than a dead-letter exchange/queue (for example, if I want to have multiple queues in the alternate-exchange with different producers so the same message can be handled in different ways).

The setup is like this:

{:ok, connection} = AMQP.Connection.open([]),
{:ok, channel} = AMQP.Channel.open(connection)
:ok = AMQP.Exchange.declare(channel, "fallback_exchange", :fanout, durable: true),
:ok = AMQP.Exchange.declare(channel, "headers_exchange", :headers, durable: true, arguments: [{"alternate-exchange", :longstr, "fallback_exchange"}])

# The regular queue(s)...
AMQP.Queue.declare(channel, "q1", durable: true)
AMQP.Queue.bind(channel, "q1", "headers_exchange", arguments: [{"h1", :longstr, "abc"}, {"x-match", :longstr, "all"}])
# ... etc...

# The dead-letter queue(s)...
AMQP.Queue.declare(channel, "misfits", durable: true)
AMQP.Queue.bind(channel, "misfits", "fallback_exchange")

I have a Broadway producer bound to "q1", and it is handling regular messages fine. But when it fails a message, that message is not sent onward to the "fallback_exchange"… it just seems to be acked and discarded.

I can see that the "misfits" queue receives messages when a message is published to the headers exchange but there were no matching bindings.

Do I have to manually publish messages back to the "fallback_exchange" in the handle_failed/2 callback? I think this will work, but I would prefer that the Broadway producer not know or care about that stuff. Is this possible? Did I configure this incorrectly?

Thanks for any guidance!

Showing Posts 1 to 1

fireproofsocks

fireproofsocks OP

I can now answer my own question:

The alternate exchange is a feature of an exchange and it kicks in when the exchange could not route a message to a queue. E.g. you send a message to a headers exchange, but the message headers do not meet any of the requirements specified by the bindings, so the first exchange hot-potato’s the message over to the alternate queue.

If you want to republish failed messages to a different exchange, that’s the job of the dead-letter exchange feature. The x-dead-leader-exchange argument is a feature of a queue, so you must define it when you define the queue (NOT the binding). If you use the RabbitMQ dashboard, you can see queues with the DLX feature. If your Broadway pipeline is processing messages from a queue with a dead-letter exchange specified, then when that pipeline fails a message (or when an exception is raised), RabbitMQ will republish that message to the dead-letter exchange.

TL;DR: alternate exchanges does not cover all the use-cases covered by the dead-letter exchange. They are related, but different.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews