Skip to content

Facilitates simple durable and asynchronous messaging in dotnet apps.

License

Notifications You must be signed in to change notification settings

Timmoth/AsyncMonolith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AsyncMonolith Logo

Ef MySql MsSql PostgreSql MariaDb

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

Overview:

  • Speed up your API by offloading tasks to a background worker.
  • Distribute workload amongst multiple app instances.
  • Execute tasks at specific times or after a delay.
  • Execute tasks at regular intervals.
  • Simplify complex processes by building out an event-driven architecture.
  • Decouple your services by utilizing the Mediator pattern.
  • Improve your application's resiliency by utilizing the Transactional Outbox pattern.
  • Improve your application's resiliency by utilizing automatic retries.
  • Keep your infrastructure simple without using a message broker.
  • Simplify testability.

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 🤝

  • 🌟 Star this repository: It means a lot to me and helps with exposure.
  • 🪲 Report bugs: Report any bugs you find by creating an issue.
  • 📝 Contribute: Read the contribution guide then pick up or create an issue.

About

Facilitates simple durable and asynchronous messaging in dotnet apps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages