Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSMQ concurrent processing design issue

I have a windows service written in C# that reads from MSMQ and based on the type of the message it assigns them to Agents that process that message in a worker thread. The application starts with no agents and are created dynamically at runtime as messages arrive in the MSMQ

Here is a basic figure of how it works:

enter image description here

If the agent worker thread is busy doing work the message is queued to its local queue. So far so good. But if for some reason if the service is stopped, the local queue content is lost.

I am trying to figure out what could be the best way to handle this scenario. Right now the local queues are a System.Concurrent.ConcurrentQueue. I could probably use a Sql Ce db or some other persistent storage, but i am worried about performance. The other thing in my mind is to read from MSMQ only when agents are ready to process message, but the problem is that I don't know what message the MSMQ will contain.

What possible approaches can I take on this issue?

like image 299
Obaid Avatar asked Jul 18 '12 06:07

Obaid


People also ask

Is MSMQ asynchronous?

Microsoft Message Queue server, short MSMQ, provides exactly that - guaranteed and reliable message delivery. It provides an easy way to send messages between different applications or to process messages asynchronously.

What is MSMQ .NET message?

The MSDN states: "Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues."

How do I know if MSMQ is enabled?

At a command prompt, run the command OptionalFeatures to open the 'Windows Features' dialog. In the feature tree of the dialog, Check the top-level feature 'Microsoft Message Queue (MSMQ) Server'. This also checks the sub-feature 'Microsoft MessageQueue (MSMQ) Server Core'.


1 Answers

Your design is basically implements the following pattern: http://www.eaipatterns.com/MessageDispatcher.html

However, rather than using actual messaging you are choosing to implement the dispatcher in multithreaded code.

Rather, each processing agent should be an autonomous process with it's own physical message queue. This is what will provide message durability in case of failure. It also allows you to scale simply by hosting more instances of the processing agent.

like image 185
tom redfern Avatar answered Sep 21 '22 12:09

tom redfern