tags:

views:

165

answers:

3

I have inherited an application that pulls messages out of an MSMQ does some processing to them and then adds some data to database depending on what is in the message. The messages are getting pushed into the Queue by a third party application I do not control.

I do not know much about MSMQ, although I do have a basic understanding of how to use the APIs.

Anyway, I have noticed that the messages never get deleted, our client definately never explictly deletes them, and I can look in computer management and see the messages back to when the server was last rebooted.

Is this wrong? Will the messages start to automatically get deleted when the queue reaches some maximum size or will they just pile up there forever slowly taking up more memory?

+1  A: 

I'd suspect that while this isn't best practice, the queue is cleared on reboot, and as long as there's a sufficient amount of resources available, you'll never actually run into a problem.

That said, I'd opt for setting something up to periodically clean up the queue so you don't overwhelm the server. I'm not too familiar with MSMQ, but is there some way that you can tell if a message has been processed? Even if it's an additional service that runs, checks the messages in the queue and sees if they already appear in the database, and deletes them if they do? That way, you wouldn't need to modify the codebase you inherited, since it's working properly as-is.

Once you decide on a solution, please post an update here - I'm interested to know how you end up dealing with this problem. Thanks!

rwmnau
We've decided on using an additional service to clean out old messages, as you suggested. This script will run once a day and delete anything from the queue older than a week. It will probably be phased out in the future, and we'll get the application to do its own housekeeping, but for now this is the simplest and quickest solution.
Nathan Reed
+3  A: 

Once a message has been processed, it is normal practice to remove it from a queue (transactionally or otherwise).

Mitch Wheat
This applies to any messaging system (e.g. WebSphere*MQ), not only MSMQ.
Richard
That's why I said 'queue' and not 'MSMQ queue ;)
Mitch Wheat
+1  A: 

"Anyway, I have noticed that the messages never get deleted, our client definately never explictly deletes them, and I can look in computer management and see the messages back to when the server was last rebooted."

Sounds like the messages are Express if there are none around from before the last reboot. Express messages are only stored in RAM and not persisted to disk so restarting the MSMQ service will destroy them. This is probably why the volume of messages has never reached a critical level.

As MSMQ uses kernel memory and disk space for memory storage, eventually one of the two would give out and cause you server stablity issues so your plan to have a cleanup process is a good one.

Cheers, John Breakwell (MSFT)

John Breakwell