Saga throws "The message cannot be accepted by an existing saga" on all messages after the first

248 views
Skip to first unread message

Achnazoor Zaprüder

unread,
Apr 7, 2014, 7:08:33 AM4/7/14
to masstrans...@googlegroups.com
Hi,

I'm having a go at setting up a saga based on the Starbucks sample (i.e. using the magnum state machine); for the time being I've reduced it to a single state change (from initial to complete), but for some reason, all messages after the first one trigger a SagaException stating that "The message cannot be accepted by an existing saga" (Thrown by InitiatingSagaPolicy.CanUseExistingInstance).


Here's the code...

The startup bit:

            WindsorContainer container = new WindsorContainer();
            container.Register(
                Component.For(typeof(ISagaRepository<>))
                    .ImplementedBy(typeof(InMemorySagaRepository<>))
                    .LifeStyle.Singleton,
                Component.For<ScriptGeneratorSaga>(),
                Component.For<IServiceBus>().UsingFactoryMethod(() =>
                {
                    return ServiceBusFactory.New(sbc =>
                    {
                        sbc.ReceiveFrom(busConfiguration.QueueAddress);
                        sbc.UseRabbitMq();
 
                        sbc.Subscribe(subs => { subs.LoadFrom(container); });
                    });
                }).LifeStyle.Singleton);
 
 
            using(IServiceBus bus = container.Resolve<IServiceBus>())
            {
                bus.WriteIntrospectionToConsole();
 
                Console.WriteLine("Press return to exit....");
                Console.ReadLine();
            }

The saga configuration:

    public class ScriptGeneratorSaga : 
        SagaStateMachine<ScriptGeneratorSaga>,
        ISaga
    {
        public IServiceBus Bus { getset; }
        public Guid CorrelationId { getset; }
 
        //mandatory start and end
        public static State Initial { getset; }
        public static State Completed { getset; }
 
        public static State Pending { getset; }
        public static State InProgress { getset; }
        
        public static State Success { getset; }
        public static State Failure { getset; }
        public static State Exception { getset; }
 
        public static Event<GenerateScriptBySiteRequestMessage> GenerateScriptBySiteRequest { getset; }
        public static Event<GenerateScriptByNetworkControllerRequestMessage> GenerateScriptByNetworkControllerRequest { getset; }
 
        static ScriptGeneratorSaga()
        {
            Define(() =>
                {
                    Initially(
                        When(GenerateScriptBySiteRequest)
                            .Then((saga, message) =>
                                {
                                    Console.WriteLine("Got GenerateScriptBySiteRequest.");
                                })
                            .Complete());
                });
        }
 
        public ScriptGeneratorSaga(Guid correlationId)
        {
            CorrelationId = correlationId;
        }
    }

The starbucks sample works fine, and I've no idea what I'm doing wrong (I've even replicated the startup process from the barista project, just in case there was something weird being done under the covers...).

I'm stumped...thoughts, anyone?

Thanks.

Chris Patterson

unread,
Apr 7, 2014, 9:48:58 AM4/7/14
to masstrans...@googlegroups.com
Are you setting the CorrelationId to a unique value for each request?


--
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/d9147487-8050-46be-a237-c95713a41564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Achnazoor Zaprüder

unread,
Apr 11, 2014, 6:08:00 AM4/11/14
to masstrans...@googlegroups.com
You're right, I missed that. :-/  
I simply assumed MT would handle it for me.
Works fine once I set the CorrelationId's myself. 

Thanks,
AWZ.


On Monday, 7 April 2014 14:48:58 UTC+1, Chris Patterson wrote:
Are you setting the CorrelationId to a unique value for each request?

Brady White

unread,
Apr 17, 2014, 10:59:13 AM4/17/14
to masstrans...@googlegroups.com
Hi Chris,

I'm receiving a similar message, but for the initial, first request.   I posted a new topic, but perhaps I should have just posted here.  Have a look in the InitiatingSagaPolicy class, in the CanUseExistingInstance method.  The code I pulled from GitHub shows that it throws the exception every time.  The version I'm using is 2.9.0.0 which I pulled from nuget.

-Brady

To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages