Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
I’ve been wanting to explore Brighter for awhile, probably over a year. I figured I’d try something new this time around and actually explore it by contributing to the project itself. I noticed there were no Command and Message Stores yet supporting MySQL. Turns out it was pretty straight forward to port the Sqlite Message & Command over to MySQL. So that’s what I did, created a Brighter MySQL Command Store.Brighter
First, if you’re unfamiliar with Brighter, here’s a quick description:This project is a Command Processor & Dispatcher implementation that can be used as a lightweight library in other projects. It can be used for implementing Ports and Adapters and CQRS (PDF) architectural styles in .NET. In addition, Brighter supports Distributed Task Queues. As such it can be used to improve performance by introducing concurrency using a queue, and/or as an integration strategy between Microservices using messaging via a lightweight broker.I like to think of Brighter as your possible next step from MediatR. Since everything in MediatR is in process, which is great in many situations, it can also be less ideal in others. When you need task queues, retry, and circuit breaker type functionality is where Brighter can help right out of the box.
Command Sourcing
Don’t confuse Command Sourcing with Event Sourcing. If you are, check out the Brighter docs that go into it a bit to clarify. Any command dispatched with Brighter can be stored. It’s actually pretty straightforward to setup. I’m going to use the newMySqlCommandStore
that I recently created as the example.
Register IAmCommandStore
First thing you need to do is register theMySqlCommandStore
as a IAmACommandStore
and/or IAmACommandStoreAsync
, in the container you are using in your HandlerConfiguration
. Here’s a modified version of the HelloWorld sample.
For reference, the two parameters in the MySqlCommandStoreConfiguration
are the connection string and the table name.
UseCommandSourcing Attribute
Second and last step is to add theUseCommandSourcing
attribute to the command handler you want to persist into command store (MySQL table).