Saga State changing

21 views
Skip to first unread message

Michael Sinnott

unread,
Sep 23, 2015, 10:43:35 AM9/23/15
to nginn-messagebus
Hi Rafal, 

I am creating a saga and I have noticed that the Saga State is changing. I have checked that the saga is not being re-instantiated and that my messages have the correct correlationId. I am not loosing all the data attached to the Saga State, just some of it. I have checked in the Sagas table, before the point where the state changes, and the data is correct. 

I'm not entirely sure if I am missing something but any ideas as to what could be causing the Saga State to change?

I hope it isn't something daft. 

Cheers, 

Mike


Rafal Gwizdala

unread,
Sep 23, 2015, 4:04:23 PM9/23/15
to nginn-me...@googlegroups.com
Michael, can you provide some more details?
a) what data are you losing and what stays in the saga? an example?
b) when do you lose the data -> is it on serialization of the state, or deserialization (I understand there's a difference in JSON you have in the database and C# state object that gets deserialized -> what is the difference?)
c) there are no errors reported?
d) I believe you figured out how saga classes are constructed in nginn-messagebus, but in case there's some misunderstanding - a fragment of code from the docs

public class SmsSaga : Saga<SmsSaga.SmsState>
{
    public class SmsState
    {
        public DateTime MessageSentDate { get; set; }
    }
}

You see the saga class declares also an internal saga state class. And it is just the state that gets serialized, not the whole saga class. I'm writing this to make sure you keep all the data in the state class (which then gets deserialized to SmsSaga.Data member).

R



--
You received this message because you are subscribed to the Google Groups "nginn-messagebus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginn-messageb...@googlegroups.com.
To post to this group, send email to nginn-me...@googlegroups.com.
Visit this group at http://groups.google.com/group/nginn-messagebus.

Michael Sinnott

unread,
Sep 24, 2015, 3:26:25 AM9/24/15
to nginn-messagebus
Hi Rafal, 

Thanks for your reply. Sorry my original post wasn't detailed enough. 

I have constructed an internal saga state class which looks like this: 

    public class FosFormExpressSagaState
   
{
       
public FosFormExpressSagaState()
       
{
           
DocumentGenerationOrder = new List<KeyValuePair<string, int>>();
           
DebtReferenceAndPaths = new List<KeyValuePair<string, string>>();
           
Collections = new List<LetterReferenceSortedItemCollection>();
           
Collection = new LetterReferenceSortedItemCollection();
       
}


       
public string Id { get; set; }
       
public string CaseId { get; set; }
       
public string CaseRef { get; set; }
       
public List<Guid> DebtIds { get; set; }
       
public List<string> DebtRefs { get; set; }
       
public string CoverLetterReference { get; set; }
       
public string LetterReference { get; set; }
       
public string DocumentType { get; set; }
       
public bool DoNotPrint { get; set; }
       
public string CreatedBy { get; set; }
       
public DateTime CreatedDate { get; set; }
       
public bool ReplyToSaga { get; set; }
       
public string GeneratedCoverLetterPath { get; set; }
       
public string FosFormExpressCommandsCount { get; set; }
       
public bool IsEsignature { get; set; }
       
public DeliveryChannelType DeliveryType { get; set; }
       
public string EmailAddress { get; set; }
       
public string MobileNumber { get; set; }
       
public List<LetterReferenceSortedItemCollection> Collections { get; set; }
       
public LetterReferenceSortedItemCollection Collection { get; set; }
       
public List<KeyValuePair<string, int>> DocumentGenerationOrder { get; set; }
       
public List<KeyValuePair<string, string>> DebtReferenceAndPaths { get; set; }
   
}


When the message is handled for the Saga, the initial set up and serialization of the Saga State is correct and viewable in the database JSON:

{
 
"Id": "7a5335e0-c540-4d2b-97e4-77c02e53cf23",
 
"CaseId": "03cb3ea1-3254-49a1-8f5f-e250d12f4f13",
 
"CaseRef": "23589",
 
"DebtIds": ["00000000-0000-0000-0000-000000000000"],
 
"CoverLetterReference": "FosClient",
 
"LetterReference": "FosClient",
 
"CreatedBy": "michaelsinnott",
 
"CreatedDate": "2015-09-23T12:57:34.1770028+01:00",
 
"FosFormExpressCommandsCount": "1",
 
"EmailAddress": "email@email.com",
 
"MobileNumber": "012345678910",
 
"Collections": [],
 
"Collection": {
 
 
},
 
"DocumentGenerationOrder": [{
 
"Key": "42092",
 
"Value": 1
 
}],
 
"DebtReferenceAndPaths": []
}

In the Saga, I then send commands out to other handlers, which reply back to the Saga. For the Saga we have InitiatedBy for 3 commands and I am aware that anything initiating the Saga could reset the Saga State however, we use the CorrelationId to keep it in sync and we also have a few other Sagas that work fine this way. 



When I handle a reply to the Saga, the Saga State looks like this:

{
 
"Id": "7a5335e0-c540-4d2b-97e4-77c02e53cf23",
 
"CaseRef": "23589",
 
"LetterReference": "FosClient",
 
"CreatedBy": "michaelsinnott",
 
"GeneratedCoverLetterPath": "C:\\printing\\23589_FosClient_20150924080721352.pdf",
 
"Collections": [],
 
"Collection": {
 
 
},
 
"DocumentGenerationOrder": [],
 
"DebtReferenceAndPaths": []
}

As you can see I lose some of the Data but not all of it, CaseRef for example. It's causing issue when I go to finalise the Saga as I have to check that the "FosFormExpressCommandsCount" matches another count before continuing and as you can see from above, it is not in the serialization of the Saga State. 

I haven't gotten any errors. 

Cheers, 

Mike

Rafal Gwizdala

unread,
Sep 24, 2015, 5:02:17 AM9/24/15
to nginn-me...@googlegroups.com
At first glance I don't see why there's a problem
The serialization should work correctly. And nginn-messagebus does not touch the saga state in any way - whatever is deserialized from the database is directly passed to c# handlers.
I would check one more thing: your saga has three InitiatedBy<> message types, which means a new instance can be created by any of these messages. Is it really the case, or only one of these messages can create a new saga? If so, please use IMessageConsumer<> instead of InitiatedBy<> for the messages that don't create new instances (you'll get better error control this way).
And another thing: did you check your database/NGSagas table for any duplicates? Maybe you have two records with same saga ID? This should never happen but let's make sure.
If nothing helps i'll try to do some testing over the weekend.
R

Rafal Gwizdala

unread,
Sep 24, 2015, 5:25:11 AM9/24/15
to nginn-me...@googlegroups.com
ps try updating to the most recent version just published - maybe you're a victim of an error (sql - saga row locking) that has been fixed in this version

Michael Sinnott

unread,
Sep 24, 2015, 6:14:25 AM9/24/15
to nginn-messagebus
Hi Rafal, 

There are no duplicates as I'm clearing out the message bus tables between testing. I have changed the InitiatedBy<> to IMessageConsumer<> and still get the issue. 

I was experimenting round and tried simplifying my Saga State Class (thinking it could have been a JSON serialization/deserialization issue) but that didn't work. 

I then tried removing my InitiatedBy<GenerateCoverLetterResponse>, the sending of that message and the handler. Leaving just the InitiatedBy<GenerateFosFormExpressCommandResponse> and the handler for it. This seemed to fix my issue. I don't get any loss of the Data attached to the Saga State but I do when Handling the response from the GenerateCoverLetterResponse. I've checked both Handlers over and I'm doing this in both:

            _currentMessageBus.Reply(new GenerateCoverLetterResponse
           
{
               
Id = message.Id,
               
Success = !String.IsNullOrEmpty(collection.MergedPath),
               
GeneratedPath = collection.MergedPath,
               
Errors = errors
           
});

Give or a take a few string properties. It does seem odd. 

I have noticed that the version we are on is 1.1.8.0 so I will have a go at upgrading to 1.2.0.0 and see if that fixes it. 

I have a workaround though as I can generate the cover letter from inside the Saga itself if I can't get the SendMessage/Handler working. 

Thanks,

Mike

Rafal Gwizdala

unread,
Sep 25, 2015, 4:11:19 AM9/25/15
to nginn-messagebus
Strange case - i have no idea what could be wrong. Please let us know if you test the new version.
R
...
Reply all
Reply to author
Forward
0 new messages