MongoDbStateMachineSagaRepository takes Parameterless SAga and I am not able to save the saga state.

103 views
Skip to first unread message

Rupesh Kumar Tiwari

unread,
Jul 2, 2015, 11:14:18 PM7/2/15
to masstrans...@googlegroups.com
       var client = new MongoClient(Settings.Default.AssemblySagaConnectionString);
            var server = client.GetServer();
            _database = server.GetDatabase(Settings.Default.AssemblySagaDatabaseName);

        configurator.Saga(new MongoDbStateMachineSagaRepository<ProcessManager>(_database));




 public class ProcessManager: SagaStateMachine<ProcessManager>, ISaga, IProcessManager
    {
    
        public static State Initial { get; set; }
        public static State Waiting { get; set; }
        public static State Cancelled { get; set; }
        public static State Completed { get; set; }
        public static State Faulted { get; set; }

  static ProcessManager()
        {
            try
            {
                Define(Saga);
            }
            catch (Exception exception)
            {
                Utility.LogAndWriteConsole(exception);
            }
        }

        public ProcessManager()
        {
            
        }
        public ProcessManager(Guid correlationId)
        {
            Status = "New";
            
            CorrelationId = correlationId;
        }



Everytime when Certain event is occurring it always goes through the EMpty Constructor and always the Status of the Saga becomes Waiting although I transition it to Completed in some other previous events. 

When I see in mongodb it always says Waiting State. It is not updating state I am not sure what is going on. I tried to store one string also called as Status in order to check if my state is persisting. But same even that string is always remains new.

Where is wrong What am I doing such that State is not persisting ?

Chris Patterson

unread,
Jul 3, 2015, 11:17:09 AM7/3/15
to masstrans...@googlegroups.com
What package are you using to save your saga to MongoDb? There isn't an official one, so curious what you're using to do it.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/f8890b90-5f53-43c7-903b-726576b05128%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rupesh Kumar Tiwari

unread,
Jul 4, 2015, 9:10:10 AM7/4/15
to masstrans...@googlegroups.com

I am using MassTransit.Persistence.MongoDb ,  I can see saga is getting persisted in the db however it's state is not persisting.

I have definition like.
During (waiting ,
    When (task1Done,
     Then(...

Anytime (when(errorOccurred)
           .Then(...)
           .TransitionTo (Faulted)

My saga sends task message in loop.
I check if 5 of any message failed I want to mark my saga faulted and stop my saga to send receive.

I saw once error message comes I transition saga into Faulted it show currentstatus fated in debug mode but when I check in db it still remains Waiting. And even though I think it is in faulted state kept getting task done messages I can never stop my saga.
         


You received this message because you are subscribed to a topic in the Google Groups "masstransit-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/masstransit-discuss/uxwykkeJHKY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
Jul 4, 2015, 3:43:56 PM7/4/15
to masstrans...@googlegroups.com
Are you using Magnum or Automatonymous?

If you use the pre-release version of Automatonymous, the CurrentState property can be an int or string, which is easy to map to something like MongoDB. 

I'm sorry but I can't help with how that persistence library is working with the property to MongoDB since it's a custom type using Magnum or the previous versions of Automatonymous.


Rupesh Kumar Tiwari

unread,
Jul 4, 2015, 8:30:10 PM7/4/15
to masstrans...@googlegroups.com

Rupesh Kumar Tiwari

unread,
Jul 6, 2015, 8:37:23 AM7/6/15
to masstrans...@googlegroups.com

Which persisting techniques you suggest.
Do you have any working sample using any other persisting way? I was preferring no sql.

Chris Patterson

unread,
Jul 6, 2015, 10:44:31 AM7/6/15
to masstrans...@googlegroups.com
It should be possible to use MongoDB with optimistic concurrency, I just haven't done it. I would ask perhaps here or on Stack Overflow to see if anyone else can help. 

There will be an official MongoDB persistence class for Automatonymous, but it's not generally available yet.

FWIW, Magnum support is deprecated in favor of Automatonymous, and Magnum will no longer be supported in MT3.


Rupesh Kumar Tiwari

unread,
Jul 6, 2015, 10:53:51 AM7/6/15
to masstrans...@googlegroups.com
Hi Chris,
I just installed nuget package masstransit.persistence.mongodb Which depends on Magnum.
Inline image 1

How can I use MongoDB with Automatonymous. Do you mean that we should wait till you upgrade the package to use Automatonymous ? 

With regards to optimistic lock, In My saga class I did not do anything to do persistence I suppose it will be done automatically once I configure my Bus to take MongoDbStateMachineSagaRepository. 
In My saga class I do not do any coding to save saga so where do I do optimistic lock etc.?   


        private static Action<ServiceBusConfigurator> Config()
        {
            var client = new MongoClient(Settings.Default.GreetingSagaConnectionString);
            var server = client.GetServer();
            var database = server.GetDatabase(Settings.Default.GreetingSagaDatabaseName);

            return sbc =>
            {
                sbc.UseLog4Net();
                sbc.UseRabbitMq();
                sbc.ReceiveFrom("rabbitmq://localhost/greeting_saga");

                sbc.Subscribe(
                    subs =>
                    {
                        subs.Saga(IoC.Resolve<MongoDbStateMachineSagaRepository<GreetingSaga>>(new ResolverOverride[]
                        {
                            new ParameterOverride("database", database)
                        }));

                        subs.Handler<GreetingRequested>(
                            msg => new GreetingRequestedHandler().Handle(msg));

                    });
            };
        }







Thanks,
Rupesh kumar Tiwari
 

Rupesh Kumar Tiwari

unread,
Jul 6, 2015, 11:42:08 AM7/6/15
to masstrans...@googlegroups.com
I was seeing your samples in Github like Starbucks etc none of them using real DB.
I don't find any working  sample with mongo. 



Thanks,
Rupesh kumar Tiwari
 

Rupesh Kumar Tiwari

unread,
Jul 7, 2015, 9:15:59 AM7/7/15
to masstrans...@googlegroups.com
Hi Chris,
Could you please point me to some sample project where I can see the AutomatonymousStateMachine saga. 
I saw there is Masstransit official plugin for Couchbase. I think I can save the saga using couchbase. 

But I want to see how to integrate AutomatonymousStateMachine with MassTransit Isaga.
Do we have some sample ?



Thanks,
Rupesh kumar Tiwari
 

Chris Patterson

unread,
Jul 7, 2015, 10:02:51 AM7/7/15
to masstrans...@googlegroups.com

Rupesh Kumar Tiwari

unread,
Jul 7, 2015, 10:18:38 AM7/7/15
to masstrans...@googlegroups.com
Thanks Chris,
It seems implementation of AutomatonymousStateMachine will be big change to our project since it is already coded with Magnum State Machine Saga. 
I will also suggest you Masstransit team to update there document to encourage people to use AutomatonymousStateMachine saga. If I go document then I always see Magnum saga sample and I motivated from there to create my project using that saga. 

Is there any way to persist my existing saga ? I can even go with SQL. 
Can you point me any sample which uses Magnum StateMachine Saga with Nhibernate since Mongo is not working. 
I have installed Masstransit nhibernate official plugin. Now want to know how to subscribe saga using NhibernateSagaRepository ?



Thanks,
Rupesh kumar Tiwari
 

Chris Patterson

unread,
Jul 7, 2015, 10:34:31 AM7/7/15
to masstrans...@googlegroups.com
You just provide the saga repository, the subscription services does it.


You really should switch to Automatonymous, I'm not sure how I could make that more clear.


Reply all
Reply to author
Forward
0 new messages