Ryan Langton
Ryan Langton

Reputation: 6160

MassTransit publish a message when all messages complete

I'm using MassTransit to manage a multiple HTTP post process and want to publish a message when all HTTP posts are complete. Is this possible to do using Sagas? I haven't found any examples of this scenario. Here's my use case example -

So the user does 4 HTTP posts (3 with data, the 4th to signify completion). The upload posts may still be processing when the user posts that the upload is complete, so I want to wait until all uploads are processed AND the upload complete post is sent, before firing another message (UploadProcessingFinished) to move on to other steps in a workflow.

Upvotes: 0

Views: 345

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33542

You could use a saga for this, yes. If there are exactly four steps, as you've described above, a single saga with four separate events. Then add a CompositeEvent to the saga that is triggered when all four of those events have been handled.

If the steps are variable prior to the completed event, you'd likely want to have either a counter of Start/Finish events from each upload, and a timeout before considering the complete command actually completed. But I would avoid that complexity if possible unless it's absolutely necessary.

Upvotes: 1

Related Questions