[Automatonymous mt2 integration] composite event error

139 views
Skip to first unread message

Egor Chikunov

unread,
Apr 10, 2015, 4:16:10 AM4/10/15
to masstrans...@googlegroups.com
Good day
I've got a trouble with using composite event in Automatonymous.MassTransit v1.2.8: composite event fires before the last event in it/
Lets say we've got a saga like this:

internal class ExampleSaga : AutomatonymousStateMachine<ExampleSagaState>
    {
        public Event<StartMsg> StartMsg{ get; private set; }

        public Event<FirstMsgCalculated> FirstMsgCalculated{ get; private set; }
        public Event<SecondMsgCalculated> SecondMsgCalculated{ get; private set; }
        public Event<ThirdMsgCalculated> ThirdMsgCalculated{ get; private set; }
              public Event AllMessagesRecieved { get; private set; }

        public State WaitingForData { get; private set; }

        public ExampleSaga()
        {
            InstanceState(c => c.CurrentState);

            InitStates();
            InitEvents();

            Initially(
                When(StartMsg)
                    .Then((state, command) =>
                    {
                        state.CalculationId = command.CalculationId;
                                    })
                    .Publish((state) => new CalculateFirstMsg(state.CalculationId))
                    .Publish((state) => new CalculateSecondMsg(state.CalculationId))
                    .Publish((state) => new CalculateThirdMsg(state.CalculationId))
                                    .TransitionTo(WaitingForData));

            During(WaitingForData,
                When(FirstMsgCalculated)
                    .Then((state, data) =>
                    {
                                              Console.WriteLine("first msg response received");
                    }),
                When(SecondMsgCalculated)
                    .Then((state, data) =>
                    {
                                               Console.WriteLine("second msg response received");
                    }),
                            When(ThirdMsgCalculated)
                    .Then((state, data) =>
                    {
                                               Console.WriteLine("third msg response received");
                    }),
                    
                When(AllMessagesRecieved)
                    .Then((state) =>
                    {
                        Console.WriteLine("done");
                    })
                    .Publish((state) =>
                    {
                                           return new CalculationEnded(state.CalculationId);
                    })
                    .Finalize());
        }

        public void ConfigureStateMachineCorrelations(StateMachineSagaRepositoryConfigurator<VirtualStocksReportSagaState> r)
        {
            r.Correlate(StartMsg, (state, message) => state.CalculationId == message.CalculationId)
                .SelectCorrelationId(message => message.CalculationId);

            r.Correlate(FirstMsgCalculated, (state, calculated) => state.CalculationId == calculated.CalculationId);
            r.Correlate(SecondMsgCalculated, (state, calculated) => state.CalculationId == calculated.CalculationId);
            r.Correlate(ThirdMsgCalculated, (state, calculated) => state.CalculationId == calculated.CalculationId);
        }

        private void InitStates()
        {
            State(() => WaitingForData);
        }

        private void InitEvents()
        {
            Event(() => StartMsg);
            Event(() => FirstMsgCalculated);
            Event(() => SecondMsgCalculated);
            Event(() => ThirdMsgCalculated);
            
            Event(() => DataRetrieved, x => x.CompositeStatus, 
                FirstMsgCalculated, 
                SecondMsgCalculated,
                ThirdMsgCalculated);
        }

Expected console result is:
first msg response received
second msg response received
third msg response received
done

but actual result is:
first msg response received
second msg response received
done
third msg response received
means CalculationEnded was published before all computation results were received.


Am i doing something wrong?

Chris Patterson

unread,
Apr 12, 2015, 11:54:39 PM4/12/15
to masstrans...@googlegroups.com
That is a weird one for sure, I can give you a cheat to fix it for now until I get it fixed in the configuration code.

Move the 
Event(() => DataRetrieved, x => x.CompositeStatus, 
                FirstMsgCalculated, 
                SecondMsgCalculated,
                ThirdMsgCalculated);
block of code to be after the first three event handlers but right before the DuringAny(WhenCompleted...) section. That will ensure the composite event is registered AFTER the other handlers for the first three events.

That's my guess anyway.

--
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/c754db27-dbdd-44b8-9c71-aee85b9fc9b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Egor Chikunov

unread,
Apr 16, 2015, 3:38:53 AM4/16/15
to masstrans...@googlegroups.com
It worked!
Thanks a million, Chris

понедельник, 13 апреля 2015 г., 6:54:39 UTC+3 пользователь Chris Patterson написал:
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