Solved

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

Posted on 2004-08-04
8
240 Views
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?
0
Comment
Question by:wsfindlater
  • 4
  • 2
  • 2
8 Comments
 
LVL 4

Accepted Solution

by:
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$$.
0
 

Author Comment

by:wsfindlater
ID: 11719750
jrandallsexton  
Think you are right. Let me try recoding, and if it is better you get the points.
0
 
LVL 4

Expert Comment

by:jrandallsexton
ID: 11719841
If you need some help with the event handler, let me know.
0
 

Author Comment

by:wsfindlater
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?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:wsfindlater
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?
0
 
LVL 10

Expert Comment

by:heintalus
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
   mq.BeginPeek()
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
                mq.BeginReceive()
            Case 1      'error processing message
                 'Shall we retry or move message to Bad Message Queue
                 If TryCount > 3 Then
                      BadMsg(imsg)
                      mq.BeginReceive()
                      TryCount =0
                 Else
                      TryCount +=1
                 End If
        End Select

        mq.BeginPeek()

    End Sub

HTH
Andy
0
 

Author Comment

by:wsfindlater
ID: 11722529
Andy,
I am impressed! Will study the code tomarrow.
Do you use timers?
Thanks,
0
 
LVL 10

Assisted Solution

by:heintalus
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.

HTH
Andy
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now