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.
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.
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.
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 new
MySqlCommandStore that I recently created as the example.
First thing you need to do is register the
MySqlCommandStore as a
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.
Second and last step is to add the
UseCommandSourcing attribute to the command handler you want to persist into command store (MySQL table).
When I run the sample app, here is the console output:
And the resulting record now stored in our MySQL database:
I plan on blogging more about Brighter in the near future. Are you using Brighter? Are there any specific features or topics you would like me to cover? Let me know in the comments or on Twitter.