What can I do to make MSMQ and Windows Services more reliable?

Posted on 2004-08-04
Last Modified: 2012-06-22
I have a Windows 2000 Server. Files are sent via FTP. A Windows Service with a timer, monitors the FTP folder, and puts a message on a MSMQ. A second Windows Service monitors this queue, and processes the file, specified in the queue message. The rate at which the second process reads the queue is controlled by a timer. Most of the time these processes work fine, but once in a while the second process stops processing the queue, and messages pile up. Have tried to debug the problem, but can not reproduce it. When I restart the second process, it processes all the messages on the queue. Has anyone else had a similar problem? What can I do to make my system more reliable?
Question by:wsfindlater
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2

Accepted Solution

jrandallsexton earned 100 total points
ID: 11719312
Why are you checking the queue on a timer?  Why don't you just handle the MessageRecived event?  I don't know if that will help or not, but I know that timers can be a pain in the a$$.

Author Comment

ID: 11719750
Think you are right. Let me try recoding, and if it is better you get the points.

Expert Comment

ID: 11719841
If you need some help with the event handler, let me know.
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.


Author Comment

ID: 11721293
OK, the event hadler has to be "shared", but I want to "re-use" functions and procedures that are not shared.
How do I pass the recieved message out from the shared event hanler, so that my old code can process the MSMQ message?

Author Comment

ID: 11721527
The thing is that I have to process the message before I receive another one. In order to process it I have make entries in the database, and send another message to the next process (simplified for the questions sake). Can I do these things from the shared procedure?
LVL 10

Expert Comment

ID: 11722345
I tend to use BeginPeek on the Queue add a handler for PeekCompleted then do my processing, then if the processing completes successfully do a BeginReceive to remove it from the queue, If it fails I do another BeginPeek to retry the operation a set number of times.  If it fails after the set amount I output the message to another queue for debugging & get ride of the original message to allow further processing.

i.e. something like this

Private TryCount as Intger
Private queuePath As String = ".\Private$\IncomingMsgs"
Private mq as MessageQueue

Protected Overrides Sub OnStart(ByVal args() As String)
   mq = New MessageQueue(queuePath)
   AddHandler mq.PeekCompleted, AddressOf MsgRcd
End Sub

Sub MsgRcd(ByVal sender As Object, ByVal e As PeekCompletedEventArgs)
        Dim arrtypes(1) As System.Type
        arrtypes(0) = GetType(IncomingMsg)
        arrtypes(1) = GetType(Object)
        mq.Formatter = New XmlMessageFormatter(arrtypes)
        Dim imsg As IncomingMsg = CType(e.Message.Body, IncomingMsg)
        Dim result As Integer

        'Try to process message
        result = ProcessMsg(imsg)

        Select Case result
            Case 0      'message processed so get rid of it
            Case 1      'error processing message
                 'Shall we retry or move message to Bad Message Queue
                 If TryCount > 3 Then
                      TryCount =0
                      TryCount +=1
                 End If
        End Select


    End Sub


Author Comment

ID: 11722529
I am impressed! Will study the code tomarrow.
Do you use timers?
LVL 10

Assisted Solution

heintalus earned 400 total points
ID: 11722641
You dont need to use timers, by using the peek method, peekcompleted is only fired when it receives a message.

Basically I've got a group of services that monitor various things on clients servers, i.e. critical events, Backup logs, various performance counters, does hardware/software audits of domain pc's etc.  All of these services fire off messages to a MSMQ which is monitored by a transfer service which forwards the info to us via a webservice.  Works very reliably.

One other thought I had about what might be causing your problem is that it might be that although you know that the file is in the FTP Folder it might not have finished being uploaded at the time your trying to process it.  It might be worth putting some error checking in there.


Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question