A couple of weeks ago, I posted about consuming Kafka events as background jobs in .NET . Today, let's look at RabbitMQ.
Writing a basic RabbitMQ consumer in C# looks easy on tutorials: you create a connection, open a channel, attach an EventingBasicConsumer or AsyncDefaultBasicConsumer , and handle messages.
Then you run it in production, and edge cases start piling up:
Long-running processing blocks the consumer. If a message takes 30 seconds to process (like calling a slow third-party API or generating a PDF), RabbitMQ's consumer_timeout (default 30 minutes in newer versions, or much less if configured) can fire and drop your channel. Worse, prefetching messages while one thread is stuck can starve other consumers.
The Ack dilemma. If you ack the message as soon as it arrives, you lose data when the worker crashes halfway through.β¦