MSMQ one (queue) to many (listeners) scenario
Asked Answered
A

3

13

I have this scenario: One client sends a message into a msmq queue instance and there are 3 processes which listen on this queue. I want to be able to let every one of those instances pick a different message and process it.

I know that is a common usage scenario for queues and i already have working code for this using MSMQ, .NET and C#.

However i am wondering if msmq is my best option here - the documentation clearly states that MSMQ is meant for "one to one" communication, meaning that there shouldnt be more than one listener.

That kind of leaves me wondering, is what i am doing the right solution for my use case? Or is it the other way round, do i have to create one queue per listener and distribute the messages in a preceeding part of the workflow?

A link to a working example demonstrating the usage of MSMQ in this type of scenario would be greatly appreciated.

Thanks

Ancy answered 15/6, 2011 at 14:53 Comment(0)
H
7

As I understand it you are using multiple listeners to do something like load balancing. This is an absolutely valid scenario and it is often used in clustered environments or in load balancing scenarios where a single listener is not able to consume all incoming messages. Btw. clustered BizTalk consumes MSMQ messages in the same way.

The one-to-one is meant as one message is passed to one listener but it doesn't mean that each queue can have only single listener. If all listeners do the same processing and it doesn't depend which one will pick the message, it is still one-to-one.

It is also possible to use one queue to deliver one message to multiple listeners. This scenario is not recommended with MSMQ even though it is technically possible with triggers.

If your listeners listen only for messages with some special properties, identifying which listener should consume the message (i.e. you search for messages in the queue), you should definitely use three queues instead.

Hanna answered 15/6, 2011 at 15:2 Comment(1)
Multicast is one message to multiple queues, not multiple listeners.Computerize
C
4

"the documentation clearly states that MSMQ is meant for "one to one" communication, meaning that there shouldn't be more than one listener."

You have a link for this?

MSMQ uses two delivery methods:
1-1 : one sender, one destination queue
1-M : one sender multicasting to many destination queues

Also, you can have multiple listeners on a queue. The number of listeners is up to you. Of course, there will be contention between multiple listeners so if you want messages to be processed only once you need to code/configure for that.

Computerize answered 15/6, 2011 at 15:16 Comment(3)
I'd like to see working code demonstrating the "best practice" of implementing this scenario: "Also, you can have multiple listeners on a queue. The number of listeners is up to you. Of course, there will be contention between multiple listeners so if you want messages to be processed only once you need to code/configure for that." For the link, i am currently searching.Ancy
Sadly I'm an MSMQ infrastructure specialist who doesn't code.Computerize
I'd like to mark yours as an answer too, since it adds to Ladislav Mrnka answer but unfortunatly that doesnt work :( Also i have tried to find the link on msdn which claims the 1-1 scenario that originally triggered this question, unfortunatly i cant find it any more.Ancy
O
1

It sounds like you need a service bus - however, they tend to be somewhat heavyweight, so it might be overkill. With a service bus, you can set up publish-subscribe scenarios in which any number of listeners can subscribe to messages. NServiceBus is a service bus that is somewhat simple to use (and it is built on top of MSMQ); there is a free version of it that is capped to 30 messages per second. Rhino ESB also claims to be lightweight.

Overexpose answered 15/6, 2011 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.