MassTransit / Automatonymous

A state machine library for .Net - 100% code - No doodleware
Apache License 2.0
736 stars 116 forks source link

Is there any option to have Fault<> consumer in MassTransitStateMachine? #54

Closed oleksiikraievyi closed 5 years ago

oleksiikraievyi commented 5 years ago

I have a saga which subscribes to response events which are produced by external services. In other words, saga publishes message, external event handler subscribed and responds to saga. These external event handlers have also Fault<> consumers. So, the question is, can saga be configured subscribe to these fault consumers ?

phatboyg commented 5 years ago

Yes, Faults can be observed by state machines.

public Event<Fault<CreateCustomer>> CreateCustomerFaulted {get; private set;}

To initialize it:

Event(() => CreateCustomerFaulted, x => x.CorrelateById(m => m.Message.Message.CommandId));

Correlating on the original message property, which is included in the fault message.

oleksiikraievyi commented 5 years ago

@phatboyg And how it works with saga subscribed ? If external event handler fails with exception n times, Fault<> handler will be triggered on this external service and saga ?

phatboyg commented 5 years ago

If a consumer throws an exception, and exhausts all retries, the Fault is published by MT. Assuming that a saga is observing that Fault event, and it can be correlated to a saga instance, either a new instance or existing instance, it would be delivered to the saga.

oleksiikraievyi commented 5 years ago

Thanks, you’ve helped me a lot