Question

Forgive me for asking a question that might have a totally obvious answer (RTFM), but how does one go about making the "Version property" mentioned here actually work? The provided links to Ayende's site here and the github repo here hint that this is possible. There is also this other SO link here that describes the same issue but does not really have a clear solution posted. I was also unable to find NSB sample code or anything in release notes or documentation related to this feature. However, it's critical knowledge for anyone running sagas with multiple worker threads and ReadCommited.

Is it really as simple as adding an integer property called Version to your saga data class and a timestamp/rowversion to your saga data table? Is this really in the samples somewhere and I'm just not looking in the right place?

Also, based on the comments I've seen posted, it looks like there is a bug in NSB 3.x that involves this feature. Will I need to upgrade to 4.x to get this feature or is there an easy way to get it working in 3.x?

Thanks!

EDIT:

Using John Simon's answer below, I ran into an bug initially using the following NSB versions:

NHibernate: 3.3.3.4001
NServiceBus: 4.3.1
NServiceBus.Host: 4.3.1
NServiceBus.Interfaces: 4.3.3
NServiceBus.NHibernate: 4.3.0
NServiceBus.StructureMap: 4.3.1

I opened this issue on github and after some back & forth, tried a dev build containing a fix and got this to work. The official fix was released in NServiceBus.NHibernate v4.4.0.

My variation on the answer was to use this with a timestamp SQL column:

[RowVersion]
public virtual byte[] Version { get; set; }

After spending a couple days hammering on it, it looks good.

Was it helpful?

Solution

In v3 all you should need to do is define a version property on the saga:

public virtual int Version {get;set;}

In v4 we default to "optimistic-all" concurrency model and if you need custom row level concurrency you do the same as v3 + an attribute:

[RowVersion]
public virtual int Version { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top