Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple clients receiving messages

205 views
Skip to first unread message

Fitzy

unread,
Jun 16, 2004, 6:19:01 PM6/16/04
to
I have written a small application in .NET that does a simple send to a MSMQ and another application that uses the ReceiveCompleted event to read the message. Is there a way that I could have two or more clients simultaneously receive messages from the same queue. The problem I currently have is that when one client receives the message, that message is removed from the queue and the other clients received event is not fired. Is there a way in MSMQ that one or more client applications can subscribe to a queue and have all the message published to that queue sent to them. I know there is the peek method and events but this reads the top message but does not remove the message from the stack, which means the client continually, gets the same message.

Any ideas would be well received.

Fitzy

unread,
Jun 16, 2004, 6:19:01 PM6/16/04
to

Fitzy

unread,
Jun 16, 2004, 6:21:02 PM6/16/04
to

Dan Kelley

unread,
Jun 17, 2004, 8:39:02 AM6/17/04
to
I personally would suggest you have 1 client that monitors the queue and performs the Receive. This object would then raise an event, which others can subscribe to, and in so doing be provided with a copy of the message.

HTH
Dan

Muhammed Ismail [MSFT]

unread,
Jun 17, 2004, 3:47:12 PM6/17/04
to
Hello,

It probably isn't a good idea to have multiple readers reading from the
same queue, why not have the messages sent to several queues (one for each
client) if each client needs to read every message. Otherwise read the
messages locally after they arrive at the destination machine, then send
them to the actual client that needs to retrieve the data. Once you
receive a message, it's removed from the queue, you could peek the message,
or navigate through the queue peeking messages. You can implement a
MessageEnumerator which should let you step through the queue, once you
find the message you want, you can receive it.

I'll reiterate that continuously stepping through the queue by applications
is probably asking for more trouble than just sending the messages to the
machines where they eventually need to be read/processed. MSMQ works best
as a transport, and even though you can read the messages remotely, i'd
suggest reading them locally whenever possible. This should also allow you
to implement transactions in the future (if you ever need to) since they
aren't supported when using remote reads.

--
Sincerely,

Muhammed Ismail
mis...@online.microsoft.com

Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Thread-Topic: Multiple clients receiving messages
>thread-index: AcRT7+1oxXeFjT2wRwuQzhUetYTj/g==
>X-WBNR-Posting-Host: 203.20.153.128
>From: "=?Utf-8?B?Rml0enk=?=" <Fi...@discussions.microsoft.com>
>Subject: Multiple clients receiving messages
>Date: Wed, 16 Jun 2004 15:19:01 -0700
>Lines: 4
>Message-ID: <4BED81E5-74C1-40C4...@microsoft.com>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.msmq.programming
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA
03.phx.gbl
>Xref: cpmsftngxa10.phx.gbl microsoft.public.msmq.programming:15396
>X-Tomcat-NG: microsoft.public.msmq.programming

Frank Boyne

unread,
Jun 19, 2004, 5:53:57 PM6/19/04
to
"Fitzy" <Fi...@discussions.microsoft.com> wrote in message
news:748FBBAD-7063-4F0B...@microsoft.com...

> Is there a way in MSMQ that one
> or more client applications can subscribe
> to a queue and have all the message
> published to that queue sent to them.

The way to have multiple receivers share messages sent to a queue is
to use Peek rather than Receive so the message isn't removed by the
first program to see the message.

Unfortuantely (as you've already discovered) Peek doesn't work well
in the System.Messaging namespace because there is no way to move
past the first message in the queue. The System.Messaging namespace
doesn't support the equivalent of PeekCurrent and PeekNext to allow
you to move down a queue past the messages you've already peeked at.

> Any ideas would be well received.

The only thing I can think of (and I'm not too keen on it) is to use
the ActiveX API from C# and use PeekCurrent and PeekNext from within
a thread started using System.Threading.Thread.

One disadvantage to the Peek approach is that _something_ has to
remove messages from the queue. What that something is, and when it
removes a message is tricky. Unless your application has some
additional structure that lets you know when a message has been
received by all clients, how do you know when it is safe to remove
the message from the queue?

You could use the Time To receive limit to let the message time out
(and so disappear) after some time has elapsed - but if you pick too
short a period then some clients may miss the message and if you
pick too big a period your queue will clog up with messages and you
may overrun the 2GB limit on the size of all messages in all queues.

As others have already pointed out, you can use the approach of
having one queue per client instead. Especially with the MSMQ 3.0
ability to send messages to multiple destinations this may be a
better bet.


Frank Boyne

unread,
Jun 19, 2004, 5:55:14 PM6/19/04
to
""Muhammed Ismail [MSFT]"" <mis...@online.microsoft.com> wrote in
message news:5wudkPK...@cpmsftngxa10.phx.gbl...

> It probably isn't a good idea to have multiple readers reading
from the
> same queue

Isn't that exactly what MSMQQueue.PeekCurrent and MSMQQueue.PeekNext
were intended for?


Frank Boyne

unread,
Jun 19, 2004, 5:57:09 PM6/19/04
to
"Dan Kelley" <DanK...@discussions.microsoft.com> wrote in message
news:7EC71B99-3227-438A...@microsoft.com...

> I personally would suggest you have 1 client
> that monitors the queue and performs the
> Receive.

That will certainly work, but you lose the asynchronous-ness of an
MSMQ application. The other clients must run synchronously with the
monitoring client in order to receive the event that's raised.


0 new messages