Solved

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

Posted on 2004-08-04
8
230 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

18 Experts available now in Live!

Get 1:1 Help Now