stefanchrobot
Handling errors in RabbitMQ consumer
I’m trying to set up a RabbitMQ consumer using the amqp library. I want to process multiple messages concurrently and properly handle errors (properly reject message if a processing error occurs). How would I go about doing this?
The “Setup a consumer GenServer” example defines a single GenServer that spawns a new process for each incoming message which paired with prefetch_count > 1 allows for concurrent processing of the messages.
How do I make sure that those processes are cleaned up properly? Is spawn_link enough to shut them down when the parent GenServer is shutting down?
Should those processes live under a supervision tree?
How would I implement a timeout for processing of a message (kill it after 5seconds)?
The example says “You might also want to catch :exit signal in production code.” Why? When would that happen? How do I do that?
Are these consumer processes a use case for Tasks or DynamicSupervisor?
Or should this be set up totally differently, i.e. have a Supervisor with N workers where each one is a consumer on a shared connection?
Most Liked
blatyo
You might find my library useful for this. It handles all the process and error stuff for you.
These slides give you idea of the code you would write.
Even if you don’t use it, you can see how those types of things are handled here.
EDIT: If you do use it and discover something that’s not well documented. Please file a ticket or a PR for it.








