Click here to Skip to main content
13,558,882 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 7 Mar 2012
Licenced CPOL

Auto Retry Concurrent Commands with ncqrs

, 7 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to auto retry concurrent commands with ncqrs

In a previous post, I showed you some pseudo code Gregory Young mentioned in his DDD CQRS course I attended in Krakow, Poland. In this course, Greg made clear to us that locking of databases isn’t necessary. He showed us some pseudo code how to easily write a merge handler to handle all concurrency conflicts.

In my current project, based on the ncqrs-framework, I implemented a simpler version of this merge handler which only retries each command if a ConcurrencyException occurs. To achieve this, you can easily build a wrapper around the ncqrs CommandService.

public class SafeCommandService : CommandService 
    public override void Execute(ICommand command)
        catch(ConcurrencyException ex)
            //Log retry executed

You can choose to implement this in a WCF service or whatever you want. Every command that fails will be retried until it succeeds. I have tested this with hundred async JavaScript calls which send a real simple command (PrintLabelCommand). My domain only processes a LabelPrintedEvent. When sending these calls to the server, my log tells me there are only 8 retries average. This is acceptable in our situation. If you have more complex scenarios, you will probably need a more advanced setup like the pseudo code in this blog post shows you.

I’m still searching for a better name for my class, because SafeCommandExecutor isn’t the best name I think. So let me know if you have a better one. I hope this article will be useful for you guys. As always, please share…

If you improved my code, let me know, so I can learn from it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Atos
Netherlands Netherlands
I am a .NET Software Developer at Atos International. Architecture, CQRS, DDD, C#, ASP.NET, MVC3, HTML5, Jquery, WP7, WPF, ncqrs, Node.js

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180515.1 | Last Updated 7 Mar 2012
Article Copyright 2012 by marcofranssen
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid