Vibhav Deo
Vibhav Deo

Reputation: 23

Is there a way to wait for the execution of a consumer in MassTransit?

In MassTransit if you want to await the execution of a consumer so that you can get the response there is IRequestClient<TCommand> which has a method GetResponse<TResponse>(Command). Is that the only way you can await the execution of a consumer in MassTransit?

What I want to be able to say is after publishing did the consumer execute successfully or did it error out if it errored out I want to be able to notify interested parties that the command errored out.

Upvotes: 2

Views: 2391

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33278

It is the easiest way, yes. If you have a method that needs to publish/send a message and wait (via await, in this case) for a consumer to consume the message, using the request client creates a unique RequestId and specifies the response address so that the consumer can notify the requestor via a response.

If you're really more interested in knowing if there was an exception consuming the message, you can create a separate consumer that consumes Fault<TCommand>. If the consumer throws an exception, MassTransit will publish a fault message of this type which can then be consumed to deal with the exception.

Note that if the request client is used, faults are only sent back to the response address and are not published.

Beyond those basic capabilities, sagas may also be used to orchestrate the original message, faults, etc. if so required.

Upvotes: 1

Related Questions