Any ideas would be well received.
HTH
Dan
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
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.
Isn't that exactly what MSMQQueue.PeekCurrent and MSMQQueue.PeekNext
were intended for?
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.