Reputation: 117
I am using an ASP.NET web project that serves a view with buttons that trigger message sends to Rebus via MSMQ. The message handlers are long running operations (15-30 minutes) and I would like the rebus command handler to send updates to the web during handling of the message.
public void Handle(ImportProducts message)
{
_bus.Send(new CommandStatusReply("Starting up import products job..."));
// One operation that takes about a minute
_bus.Send(new CommandStatusReply("Step one completed. processing..."));
// Another operation that takes a while
...
}
In my web application I have a handler for CommandStatusReply that will push the status message to the client via SignalR. Everything works except that all CommandStatusReply-messages are sent "in a batch" when the ImportProducts message has been handled. I would like them to be sent immediately instead. Is this possible? In that case, what am I missing?
I have tried Bus.Send(), Bus.Reply() and Bus.Publish() and also tried wrapping the Bus.Reply/Send in a TransactionScope(TransactionScopeOptions.Suppress) to no avail.
Upvotes: 4
Views: 452
Reputation: 18628
You could use another bus for reporting the progress, but you'd need to use another transport as well - otherwise, the other bus will enlist its MSMQ send operation in the same MSMQ transaction that received the message currently being handled, and you'd still have the same atomic commit of all queue operations after the message has been successfully handled.
IMO the bus is not really suitable for reporting progress like that - I'd prefer something more lightweight, like e.g. SignalR.
You can easily use SignalR from your Rebus handler to call into your SignalR hub and have the hub publish progress to the client(s) - I've done this myself a couple of times, and it works like a charm :)
Upvotes: 2