Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-04
8
Medium Priority
?
294 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 400 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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
 

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 1600 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
Screencast - Getting to Know the Pipeline

773 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