0

I am using request reply model of NServiceBUs for one of my project.There is a self hosted service bus listening for a request message and reply back with a request message. So in WCF message code i have coded like

// sent the message to bus.
var synchronousMessageSent = 
    this._bus.Send(destinationQueueName, requestMessage)
    .Register(
        (AsyncCallback)delegate(IAsyncResult ar)
        {
             // process the response from the message.
             NServiceBus.CompletionResult completionResult = ar.AsyncState as NServiceBus.CompletionResult;
             if (completionResult != null)
             {
                 // set the response messages.
                 response = completionResult.Messages;
             }                                                     
        }, 
        null);

       // block the current thread.
        synchronousMessageSent.AsyncWaitHandle.WaitOne(1000);
       return response;

The destinaton que will sent the reply. I am getting the resault one or tweo times afetr that the reply is not coming to the client. Am i doing anything wrong

Greg B
  • 14,597
  • 18
  • 87
  • 141
Ajai
  • 1
  • 1
  • Consider this: http://stackoverflow.com/questions/3758405/nservice-bus-message-delay-problem – mynkow Oct 18 '10 at 18:31

1 Answers1

4

Why are you trying to turn an a-synchronous framework into a synchronous one? There is a fundamental flaw with what you are trying to do.

You should take a long hard look at your design and appreciate the benefits of a-sync calls. The fact that you are doing

// block the current thread.
synchronousMessageSent.AsyncWaitHandle.WaitOne(1000);

Is highly concerning. What are you trying to achieve with this? Design your system based on a-synchronous messaging communication and you will have a MUCH better system. Otherwise you might as well just use some kind of blocking tcp/ip sockets.

mike
  • 3,146
  • 5
  • 32
  • 46
  • 1
    Downvoted not an answer. If NServiceBus doesn't support it, then say it doesn't support it and maybe offer why that might be and then maybe an opinion. This "answer" is purely an opinion (whether or not it is the best practice, or warning, disagreement, option, etc.) – Sinaesthetic Nov 29 '16 at 19:57