marknijhof / fohjin Goto Github PK
View Code? Open in Web Editor NEWThis is a personal sand box
Home Page: https://leanpub.com/cqrs
This is a personal sand box
Home Page: https://leanpub.com/cqrs
# CQRS, the book In 2009 I have had the pleasure of spending a 2 day course and many geek beers with Greg Young talking about Domain-Driven Design specifically focussed on Command Query Responsibility Segregation (CQRS). The example project I created based on these discussions was very well received by the community and regarded a good reference project to explain and learn the patterns that make up CQRS. I decided to add the different blog posts I wrote about the example into a single book so it is easy to find and read. You can find the book here: https://leanpub.com/cqrs --- # x86 vs x64 When running the example on a x86 machine you have to go into the /Lib/sqlite/bin/ folder and copy the three System.Data.SQLite.* files into the /Lib/sqlite/bin/x64/ folder. This is because I am developing on a x64 system. An interesting fact is that the TestDriven.Net test runner does actually run in x86 mode, so the SQLite reference in the Test project is the the x86 SQLite version already. Resharper test runner acts the same. If you have any questions or other feedback then I would love to hear about it at [email protected] -Mark
Mark:
Hello, and how are you doing? I hope this message finds you doing well!
I’ve a question for you concerning you’re (awesome!) CQRS implementation…
It has to do with setting up a “Message Queue” for incoming commands from a Client.
There are many ideas that suggest that a message queue can be used to publish Commands to the Event Store.
My application demands that a lot of clients will be issuing a lot of commands and a message queue of some kind is a highly recommended strategy for Distributed Services (as I’m sure you’re well aware of… )
The above diagram depicts the current implementation of my Message Queue (using NetMq.ReactiveExtensions); and, I must say: it was dead-easy to do, too.
Web API Controller
// Create Securities. else if ( secsDto.ActionType.Equals( DbActionType.Create ) ) { var cmd = new CreateSecuritiesCommand( id: Guid.NewGuid() , securitiesReport: secsDto.SecuritiesReport ); var json = JsonConvert.SerializeObject( cmd ); m_Publisher.Publish( json ); await Task.Delay( 1000 ); }
Publisher
public void Publish( string message ) { // Publish the command on the Message Bus. var cmd = JsonConvert.DeserializeObject<CreateSecuritiesCommand>( message ); var publisher = new PublisherNetMq<string>( m_EndPoint , loggerDelegate: msg => WriteLine( msg ) ); publisher.OnNext( message ); WriteLine( $"Published: {message}" ); }
Subscriber
public void Subscribe() { subject.Subscribe( ( m ) => { // Valid JSON object. if ( string.IsNullOrEmpty( m ).Equals( false ) ) { var cmd = JsonConvert.DeserializeObject<CreateSecuritiesCommand>( m ); if ( m_Bus != null && cmd != null ) { // Publish on Command Bus. WriteLine( $"Received: {cmd.Id} , {cmd.SecuritiesReport.Id} , {cmd.SecuritiesReport.Ticker}" ); m_Bus.Publish( cmd ); m_Bus.Commit(); } } } ); }
The above is my simple demonstration and really works quite nicely.
I would prefer to use this implementation, as opposed to messing around with your beautifully constructed
Command Registration Action Method:
public Action<TCommand> CreatePublishActionWrappedInTransaction<TCommand, TCommandHandler>( TCommandHandler commandHandler , ref IContainer container ) { var trans = container?.GetInstance<TransactionHandler<TCommand , TCommandHandler>>(); return ( ( c ) => { trans?.Execute( c , commandHandler ); // Move this somewhere else… }); }
… and performing the Publish here…. And then in the Subscriber, actually performing the Commit…. Just seems like I’d have to re-wire a lot of your existing code (which, as I mentioned I don’t want to do because I like the way you’ve done Configuration).
Again, Mark thank you for all you’re wonder work on this project.
Please Advise,
Robert Hyland
President & CEO,
Hyland Computer Systems, L.L.C
E: [email protected]
Would you accept a pull request with this done? I would try not to touch any code at all... just pure dependency cleanup to nuget and away from hard references in the lib folder.
Hi Mark,
I really enjoyed your CQRS series of posts. Thanks for sharing.
The source code on github does not contain any information on licensing the code.
Cheers,
Josh
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.