I want to replace my messaging system with Rebus but I need to execute some messages synchronously.
My webapi controller needs to wait until all handlers to complete.
"Client -> Controller -> Bus (Tx1 Begin -> Handler1 - Handler2 -> Tx1 Complete) -> Http.OK"
Do you have any idea how can I implement this?
Thanks,
There's no way at the moment, but nothing prevents you from having a handler in the background that puts received replies into a static ConcurrentDictionary<string, Reply>
, which you can then periodically poll for the reply that corresponds to e.g. a correlation ID of a message that you have sent.
You could either wrap the waiting in an await
able method that returns a Task
, or you might want to take a look at ManualResetEvent if you want to block the thread until the replies were received.
You would of course have to do this with two dictionaries, or build in another mechanism that is capable of waiting for multiple replies.
This is usually not the best way to correlate replies though, so I'm curious to hear what you're trying to achieve?