0

I have a MT state machine which is configured with UseInMemoryOutbox() so any messages that are part of the event handling will be published only after the final step in the pipeline is successfully done, which in my case is, state persistence to Couchbase.

        Initially(When(A).
                    ThenAsync(async context =>
                    {   
                        context.Instance.IsAutoApprove = context.Data.IsAutoApprove;
                        IList<Task> publishTasks = context.Data.SomeList.Select(item =>
                        {
                            MessageA message = new MessageA
                            {
                                Content = "contentA"
                            };
                            return context.Publish(message);
                        }).ToList();

                        await Task.WhenAll(publishTasks);
                    }).TransitionTo(B));

        WhenEnter(B, f => f.If(c => c.Instance.IsAutoApprove,
            callback =>
            callback.TransitionTo(C)
            ));

        WhenEnter(C, c => c.Publish<SagaState, MessageC>(context =>
                     new MessageC
                     {
                         Content = "contentC"
                     }));

I've noticed that the publish messages are published eventually, in an inconsistent order.

For example - assume there are two items within the "SomeList" in the first event, so the messages are published sometimes in this order:

MessageC
MessageA
MessageA

and sometimes

MessageA
MessageA
MessageC

and so on. The order of the logical flow is not preserved.

Can you please assist me with this behavior?

I'm using

MassTransit 3.5.2

MassTransit.Automatonymous 3.5.2

MassTransit.RabbitMQ 3.5.2

Automatonymous 3.5.11

GreenPipes 1.0.9

Thanks,

  • To be honest, I would _never_ expect messages come in a specific order. RabbitMQ does not provide such guarantees, it is not wise to rely on that. – Alexey Zimarev Jul 24 '17 at 16:45

1 Answers1

0

This was something that was done for performance reasons, but doesn't really make sense, so I've submitted an issue and closed it.

https://github.com/MassTransit/MassTransit/issues/945

With v4, actions will be executed in order.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59