Take the 2-minute tour ×

Another question on the Using NServiceBus with Asp.Net MVC 2 thread. Udi has replied saying following method can be used if we really want to do it.

var sync = Bus.Send<SomeMessage>(/*data*/)
            .Register((AsyncCallback)delegate(IAsyncResult ar)
                              var result = ar.AsyncState as CompletionResult;
                              // do something with result.Messages

           sync.AsyncWaitHandle.WaitOne( /*timeout*/);

This will work perfectly in a windows application, because there is only one user.

I wonder how this will work in a web application; since there are multiple threads (for multiple user sessions) call Bus.Send and waiting for the callback. There will be only one reply queue (if my understanding is correct).

Does NServiceBus know which thread to resume based on the response message it received from queue?

If my understanding is correct, it's not recommended to use messaging for these kind of scenarios (send a request message from a web Application to a Service, which handle the message and reply with a response message)

"For example, if you want to perform queries like GetCustomersByRegionRequest and CustomersByRegionResponse, that should not be implemented using messaging." - http://www.nservicebus.com/Documentation.aspx

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Internally NSB keeps this all together by maintaining a dictionary of the callbacks and their associated messages. The messages have a correlation id that is used to do the lookup. You are correct, using message in a Request/Response scenario really defeats the purpose of messaging. The main purpose is to not block, wherein Request/Response inherently is a blocking pattern. See the response from Andreas in the post above, it has a good explanation.

share|improve this answer

Your Answer


