MongoDbSagaRepository weirdness

65 views
Skip to first unread message

Sandro Lange

unread,
May 17, 2016, 7:53:02 AM5/17/16
to masstransit-discuss
We are currently playing around with SagaStateMachine and when using the InMemorySagaRepository everything works as expected, when I shutdown the process running a saga, the state is not persisted.

Now we are exploring some persistance options and run into multiple problems:

- The MongoDBSagaRepository seems to be our most prefererred persistor as we are already using MongoDB for a couple of other things and it seems there is not much to configure - however it is not really working:

We have defined a SagaStateMachineInstance:

 public class NewMail : SagaStateMachineInstance, IVersionedSaga
    {
        [BsonId]
        public ObjectId Id { get; set; }      // why do we need an ObjectId field? If we don't provide one we get a serialization error stating that now property matching "_id" was found!
        public State State { get; set; }      // here we get an "Unknown discriminator value" error - seems to be some serialization problem

        public IImportNewEMailRequest Request { get; set; }

        public Guid CorrelationId { get; set; }

        public IList<IImportNewEMailRequest> MessagesToProcess { get; set; }

        public Dictionary<Guid, List<Guid>> UserFolders { get; set; }
        public IList<Guid> UsersNotToNotify { get; set; }
        public int Version { get; set; }
    }


The state seems to be persisted like this:

 {"_id":"ObjectId(573ad35e7de3c1a3fc59392b)","State":{"_t":"StateMachineState`1"},"Request":null,"CorrelationId":"LUUID(70f282bf-af6f-b848-ad45-b3b3ade0603e)","MessagesToProcess":null,"UserFolders":null,"UsersNotToNotify":null,"Version":0}

Now when we try to load a state we run into trouble:

- First we need an ObjectId for some reason (see comment above)
- second it does not seems to serialize State the correct way (we get an "Unknown discriminator value")
- Other, more complex interfaces are not serialized either 

It seems we either using it the wrong way or we are missing some important steps.

The most ideal way would be to persist the SagaState inside RabbitMq but this does not seems to be possible. We don't know what to do with the other persistors like EntityFramework and NHibernate - we have already spend a lot of time into the Saga thing itself due to the lack of documentation - well the basic documentation is there but important things like catching exceptions, how to use the filter criterias in a when clause etc. are simply not too well documented - we are looking at the unit tests for the most parts but this does not make it any easier :(


Sandro Lange

unread,
May 17, 2016, 8:11:19 AM5/17/16
to masstransit-discuss
Another issue is that it seems to create duplicate entries in the database - or at least entries with the same state and the same correlationId ... I'm giving up ...
Reply all
Reply to author
Forward
0 new messages