If you've ever wondered how to run asynchronous, long running tasks without blocking your API responses and without pulling in external dependencies like Hangfire or RabbitMQ this might interest you.
In my latest article on ABP Community, I walk through how to build an in memory background job queue from scratch using only built in .NET tooling (IHostedService
, System.Threading.Channels
, dependency injection, etc.). It’s ideal for scenarios where you need lightweight queueing in a single application instance (with the usual caveats). 👇
What you’ll learn
- How to define a
IBackgroundTaskQueue
interface - Implementing it using
Channel<T>
- Creating a
BackgroundService
that continuously dequeues and executes jobs - Wiring it into the ASP.NET Core DI container
- Pitfalls and limitations of an in memory approach (e.g. job loss upon restart, scalability)
- When to switch to more robust solutions (Hangfire, message brokers)
If you like hands on, from scratch tutorials, here’s the full article:
How to Build an In Memory Background Job Queue in ASP.NET Core from Scratch
Top comments (0)