Saga using Sql Persistence - Correlation Property Name

156 views
Skip to first unread message

Mick Anderson

unread,
Aug 16, 2017, 1:16:45 PM8/16/17
to Particular Software
Helpful information to include
Product name:  Nservicebus Sql Persistence
Version:  Latest of Each
Stacktrace:
Description:

I am currently working on a POC to move from Ravendb to Sql Persistence to see how this new persistence option works.  I was working on creating a Saga similar to how the documentation for the simple sql persistence  (https://docs.particular.net/samples/sql-persistence/simple/).  When build the solution after creating it i am getting this build error:  


Error SqlPersistenceTask: Error in 'mwa.POC.SqlPersistence.Backend.TestPOCSaga'. Error:Only a direct string (or null) return is allowed in 'mwa.POC.SqlPersistence.Backend.TestPOCSaga.CorrelationPropertyName'.
For example: protected override string CorrelationPropertyName => nameof(SagaData.TheProperty);
When all messages are mapped using finders then use the following: protected override string CorrelationPropertyName => null;


We are a vb.net shop but here is the section of the code it is throwing the build error on:

Protected Overrides ReadOnly Property CorrelationPropertyName As String
    Get
        Return NameOf(TestPOCSagaData.CorrelationId)
    End Get
End Property

Is there something i am missing when i'm setting this up?

Thanks,
Mick

Szymon Pobiega

unread,
Aug 17, 2017, 1:11:04 AM8/17/17
to particula...@googlegroups.com
Hi Mick

I found the problem. The script generation code runs on build time and needs to be able to know the correlation property name without actually executing the code in the saga. Instead, we use Mono.Cecil to inspect the bytecode of the CorrelationPropertyName property to find out what is the returned value. The current code expects only two opcodes in that method:
 * ldstr or ldnull for preparing the result
 * ret for returning

A decompiled C# code would be

IL_0000: ldstr        "Class1"
IL_0005: ret

What I found out and was totally surprised by this is that a similar VB code results in the following IL:

IL_0001: ldstr        "TestPOCSagaData"
IL_0006: stloc.0      // V_0
IL_0007: br.s         IL_0009
IL_0009: ldloc.0      // V_0
IL_000a: ret          

For some reason VB insists on storing the value in a local variable, jumping one instruction just to load it back. We'll have to change the IL inspection method. As a temporary workaround you can disable the script generation (by not referencing the NServiceBus.Persistence.Sql.MsBuild package) and use the scripts provided in the documentation: https://docs.particular.net/persistence/sql/sqlserver-scripts#build-time-saga-create-table. The subscription, timeouts and outbox scripts can be used without modification. The saga tables differ only by correlation property name column/type.

Hope it helps,
Szymon


--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.
To post to this group, send email to particularsoftware@googlegroups.com.
Visit this group at https://groups.google.com/group/particularsoftware.
To view this discussion on the web visit https://groups.google.com/d/msgid/particularsoftware/2f4eb4fb-8352-4b37-917f-db0d594bb024%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Have you tried NServiceBus V6 yet?

Learn how to scale applications with microservices and NServiceBus 6.


Join Udi Dahan's next Advanced Distributed Systems Design Course:

September 2017 Los Angeles, CA, USA

November 2017 Sydney, Australia


Szymon Pobiega

unread,
Aug 17, 2017, 5:04:59 AM8/17/17
to particula...@googlegroups.com
Hi Mick

A quick update. The root cause of the problem was the lack of support for statement-bodied properties in the current version of SQL persistence. The difference is, not as I wrote in the previous message, between VB and CS but between expression and statement-style bodies. The error you encounter also shows up when using statement-style properties in CS. Unfortunately VB does not support expression-body syntax (e.g. protected override string CorrelationPropertyName => nameof(SagaData.Correlation)).

The fix is here https://github.com/Particular/NServiceBus.Persistence.Sql/pull/146 and will be shipped in the upcoming 3.0 release.

Thanks for reporting this,
Szymon

To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsubscribe@googlegroups.com.
--

Have you tried NServiceBus V6 yet?

Learn how to scale applications with microservices and NServiceBus 6.


Join Udi Dahan's next Advanced Distributed Systems Design Course:

September 2017 Los Angeles, CA, USA

November 2017 Sydney, Australia


Mick Anderson

unread,
Sep 1, 2017, 8:26:50 AM9/1/17
to Particular Software
Thanks for the update Szymon!   Is there a rough date for when 3.0 is going to be released?

Thanks,
Mick
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
--

Have you tried NServiceBus V6 yet?

Learn how to scale applications with microservices and NServiceBus 6.


Join Udi Dahan's next Advanced Distributed Systems Design Course:

September 2017 Los Angeles, CA, USA

November 2017 Sydney, Australia


Weronika Labaj

unread,
Sep 1, 2017, 9:53:29 AM9/1/17
to Particular Software
Hi Mick, 

We're preparing a beta release for 3.0, so stay tuned! It should be out very soon.

Weronika

Szymon Pobiega

unread,
Sep 7, 2017, 7:29:02 AM9/7/17
to particula...@googlegroups.com
Hi Mick

Because in the meantime we had to re-target the V3 release of SQL persistence from V6 to V7 of NServiceBus, we have just released a patch 2.1.4 which includes the fix to statement-type properties for Version 6 of NServiceBus/Version 2 of SQL persistence. If you upgrade to 2.1.4 you should be able to build the scripts normally.

Cheers,
Szymon

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.
To post to this group, send email to particularsoftware@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages