Loading...
Loading...
Marco Franssen

In a previous post, I shared some pseudocode Gregory Young presented during the DDD/CQRS course I attended in Krakow, Poland. In this course, Greg explained that database locking isn't necessary. He showed us how to write a merge handler to handle concurrency conflicts.
In my current project, based on the Ncqrs framework, I implemented a simpler version of this merge handler that retries a command whenever a ConcurrencyException occurs. To achieve this, you can build a wrapper around the Ncqrs command service.
public class SafeCommandService : CommandService
{
public override void Execute(ICommand command)
{
try
{
base.Execute(command);
}
catch(ConcurrencyException ex)
{
Execute(command);
//Log retry executed
}
}
}You can implement this in a WCF service or wherever you need it. Every command that fails with a concurrency exception will be retried until it succeeds. I tested this with a hundred asynchronous JavaScript calls that send a very simple command (PrintLabelCommand). My domain only processes a LabelPrintedEvent. When I send these calls to the server, my log shows an average of only eight retries. This is acceptable in our situation. If you have more complex scenarios, you'll probably need a more advanced setup, like the pseudocode in this blog post.
I'm still searching for a better name for my class, because I don't think SafeCommandService is the best name. Let me know if you have a better one. I hope this article is useful for you. As always, please share…
If you've improved my code, let me know so I can learn from it.
Marco Franssen
Write a personal elevator pitch that highlights your strengths, builds credibility, and invites a conversation with practical tips on persuasion.
Marco Franssen
Write modular JavaScript with the module pattern, private functions, and a shared namespace to avoid global name collisions and organize dependencies.
Marco Franssen
Install Windows 8 Developer Preview on a virtual hard disk and boot it alongside Windows 7, using a bootable USB drive and diskpart.
Marco Franssen
Use jQuery events and a mediator to connect independent JavaScript modules, keeping a product dialog and grid separate while they communicate.