Link to home
Start Free TrialLog in
Avatar of matt_d_p
matt_d_p

asked on

Timeout receiving asyncronous message using msmq

Hi

I'm trying to learn more about messaging and services using an example by Peter Bromberg from Egghead Cafe (http://www.eggheadcafe.com/articles/20041204.asp - code can be downloaded from http://www.eggheadcafe.com/articles/20041204.zip). The example runs on a single machine but I've been trying to get it to run with the client and server on seperate machines for about 3 days without luck. I added event log messages at different points and it seems to fall over at the async receive on the server (Invoker.cs in the MSMQInvokerService project):

try
                  {
                                //breaks at this point
                                Message msg=mq.EndReceive(ar);
                                //and goes to the catch
                        ICommand cReceived = (ICommand)msg.Body;
                        ServiceBroker.Logger.WriteToLog("ICommand Object Casted.",
                                                System.Diagnostics.EventLogEntryType.Information);
                        cReceived.Execute();
                        ServiceBroker.Logger.WriteToLog("Executed Command at "+DateTime.Now.ToLongTimeString(),
                                                System.Diagnostics.EventLogEntryType.Information);
                  }
                  catch
                  {
                        ServiceBroker.Logger.WriteToLog("Timeout!",
                                                System.Diagnostics.EventLogEntryType.Information);
                  }

If the service is invoked on the server this means that the message has gotten there, right? What am I doing wrong?

Matt
Avatar of dstanley9
dstanley9

One thing you may try is to post the exception to the event log to see if it actually was a timeout:

               catch(Exception exception)
               {
                    ServiceBroker.Logger.WriteToLog("An Exception Occured:\n" + exception.ToString(),
                                        System.Diagnostics.EventLogEntryType.Information);
               }
Avatar of matt_d_p

ASKER

Thanks for the suggestion. Seems it is a timeout out but why? Why the difference between local and remotes? I'm on a home network with 2 pc's linked by a crossover cable. Shouldn't be any load at all.

This is the error in the remote log:

Event Type:      Information
Event Source:      ServiceBroker
Event Category:      None
Event ID:      0
Date:            2006/06/07
Time:            09:45:44 PM
User:            N/A
Computer:      BIGBLACK
Description:
An Exception Occured:
System.Messaging.MessageQueueException: Timeout for the requested operation has expired.
   at System.Messaging.MessageQueue.AsynchronousRequest.End()
   at System.Messaging.MessageQueue.EndAsyncOperation(IAsyncResult asyncResult)
   at System.Messaging.MessageQueue.EndReceive(IAsyncResult asyncResult)
   at MSMQInvokerService.Invoker.OnMessageArrival(IAsyncResult ar)

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

While playing I've also introduced a bug in the client now:

FormatName:DIRECT=OS:bigblack\private$\commandtest              //writeline of destinationQueue value
System.Messaging.MessageQueueException: The specified format name does not suppo
rt the requested operation. For example, a direct queue format name cannot be de
leted.
   at System.Messaging.MessageQueue.SaveQueueProperties()
   at System.Messaging.MessageQueue.set_UseJournalQueue(Boolean value)
   at ClientSample.QueuedClient.QueueInvokerCommand(ICommand c, String destinati
onQueue) in C:\projects\PosMinder\ClientSample\QueuedClient.cs:line 65

Could this contribute? It complains about the name format yet still seems to get to the server as I see the errors there. Very confusing?
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I understand this correctly, there isn't a problem at the server, the server just writes this message each time it "times out" while checking for a message? That explains why I couldn't find anything wrong :). Let me go and find my real problem. Thanks for the help.
Yes, the ReceivedCompleted event will fire in the event of a timeout, but calling EndReceive if there is no message will cause the exception.  

You can check the IsCompleted property of the AsyncResult object to see if a message was actually received.