Solved

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

Posted on 2004-08-04
8
267 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
[X]
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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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