Composite State Machine Events
A composite event is configured by specifying one or more events that must be consumed, after which the composite event will be raised. A composite event uses an instance property to keep track of the required events, which is specified during configuration.
To define a composite event, the required events must first be configured along with any event behaviors, after which the composite event can be configured.
public class OrderState : SagaStateMachineInstance{ public Guid CorrelationId { get; set; } public string CurrentState { get; set; }
public int ReadyEventStatus { get; set; }}
public class OrderStateMachine : MassTransitStateMachine<OrderState>{ public OrderStateMachine() { Initially( When(SubmitOrder) .TransitionTo(Submitted), When(OrderAccepted) .TransitionTo(Accepted));
During(Submitted, When(OrderAccepted) .TransitionTo(Accepted));
CompositeEvent(() => OrderReady, x => x.ReadyEventStatus, SubmitOrder, OrderAccepted);
DuringAny( When(OrderReady) .Then(context => Console.WriteLine("Order Ready: {0}", context.Saga.CorrelationId))); }
public Event OrderReady { get; private set; }}Once the SubmitOrder and OrderAccepted events have been consumed, the OrderReady event will be triggered.