Can I filter the messages I receive from a message queue (MSMQ) by some property? (a.k.a. topic)

StackOverflow https://stackoverflow.com/questions/64204

  •  09-06-2019
  •  | 
  •  

Question

I am creating a Windows Service in C# that processes messages from a queue. I want to give ops the flexibility of partitioning the service in production according to properties of the message. For example, they should be able to say that one instance processes web orders from Customer A, another batch orders from Customer A, a third web or batch orders from Customer B, and so on.

My current solution is to assign separate queues to each customer\source combination. The process that puts orders into the queues has to make the right decision. My Windows Service can be configured to pull messages from one or more queues. It's messy, but it works.

Was it helpful?

Solution

No, but you can PEEK into the queue and decide if you really want to consume the message.

OTHER TIPS

Use GetMessageEnumerator2() like this:

MessageEnumerator en = q.GetMessageEnumerator2();

while (en.MoveNext())
{
    if (en.Current.Label == label)
    {
        string body = ((XmlDocument)en.Current.Body).OuterXml;
        en.RemoveCurrent();
        return body;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top