Home

Awesome

AsyncMonolith Logo

Ef MySql MsSql PostgreSql MariaDb

AsyncMonolith is a lightweight library that facilitates simple, durable and asynchronous messaging in dotnet apps.

Overview:

[!NOTE]
Despite its name, AsyncMonolith can be used within a microservices architecture. The only requirement is that the producers and consumers share the same database i.e messaging within a single project. However, it is not suitable for passing messages between different projects in a microservices architecture, as microservices should not share the same database.

Find out more 🤔

Check out this video from Derek Comartin, for some thoughts on using a database as a queue

Guides

Posts

Quick Demo

Producing and scheduling messages

  // Publish 'UserDeleted' to be processed in 60 seconds
  await _producerService.Produce(new UserDeleted()
  {
    Id = id
  }, 60);
  
 // Publish 'CacheRefreshScheduled' every Monday at 12pm (UTC) with a tag that can be used to modify / delete related scheduled messages.
 _scheduleService.Schedule(new CacheRefreshScheduled
   {
       Id = id
   }, "0 0 12 * * MON", "UTC", "id:{id}");
 await _dbContext.SaveChangesAsync(cancellationToken);

Consuming messages

[ConsumerTimeout(5)] // Consumer timeouts after 5 seconds
[ConsumerAttempts(1)] // Consumer messages moved to poisoned table after 1 failed attempt
public class DeleteUsersPosts : BaseConsumer<UserDeleted>
{
    private readonly ApplicationDbContext _dbContext;

    public ValueSubmittedConsumer(ApplicationDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public override Task Consume(UserDeleted message, CancellationToken cancellationToken)
    {
        ...
		await _dbContext.SaveChangesAsync(cancellationToken);
    }
}

Collaboration 🙏

Like the idea and want to get involved? Check out the open issues or shoot me a message if you've got any ideas / feedback!

Support 🛟

Need help? Ping me on linkedin and I'd be more then happy to jump on a call to debug, help configure or answer any questions.

Discord

Come say hello on the Discord server

Support the project 🤝