Menu

Consuming RabbitMQ Messages as Background Jobs in .NET with NexJob
πŸ“°

Consuming RabbitMQ Messages as Background Jobs in .NET with NexJob

DEV Community: dotnetΒ·Luciano AzevedoΒ·5 days ago
#U9edfzoL
#devtodotnet#devto#dev#rabbitmq#nexjob
Reading 0:00
15s threshold

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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.