Discussion:
Delete Specific Message in MSMQ
(too old to reply)
emy
2005-01-19 07:03:16 UTC
Permalink
I want ask is it possible for me to delete a specific message in
msmq??I'm using MSMQ 2.0...because as far as i read...i have to peek
the message that i want to delete first before i can receive it...but
the problem rise when total of message inside a queue is a lot...can
anyone please help me...Thank u..
Doron Juster [MSFT]
2005-01-19 12:23:19 UTC
Permalink
Yes, if you want to delete a specific message at a random place in the queue
then you must use a cursor to navigate to the message, then you can delete
it.

Thanks, Doron
--
This posting is provided "AS IS" with no warranties, and confers no rights.
.
Post by emy
I want ask is it possible for me to delete a specific message in
msmq??I'm using MSMQ 2.0...because as far as i read...i have to peek
the message that i want to delete first before i can receive it...but
the problem rise when total of message inside a queue is a lot...can
anyone please help me...Thank u..
Dejan Grujic
2005-01-19 18:58:49 UTC
Permalink
Technicaly you don't have to peek message - if you have id you can just
use ReceiveById to delete it.
However practically you got Id by peeking or by
GetPrivateQueuesByMachine or some similar method (I'm talking about
doing this from .Net).

Dejan
--
QueueExplorer - manage MSMQ messages like they are files
http://www.cogin.com/mq/
Yoel Arnon
2005-01-20 22:00:54 UTC
Permalink
Please note that ReceiveById simply traverses the queue serially till the
requested message, so it is not more efficient than doing this loop
yourself.

MSMQ 3.0 has ReceiveByLookupId (currently available only using the COM
interface) which is an efficient way to receive & delete a message that was
once Peeked.

How can you use GetPrivateQueuesByMachine to get a message ID?

Hope that Helps,
Yoel
www.msmq.biz
Post by Dejan Grujic
Technicaly you don't have to peek message - if you have id you can just
use ReceiveById to delete it.
However practically you got Id by peeking or by GetPrivateQueuesByMachine
or some similar method (I'm talking about doing this from .Net).
Dejan
--
QueueExplorer - manage MSMQ messages like they are files
http://www.cogin.com/mq/
Dejan Grujic
2005-01-23 15:51:25 UTC
Permalink
Good to know about how ReceiveById works. Unfortunately I can't use
ReceiveByLookupId because it's not supported from .Net 1.1.
About GetPrivateQueuesByMachine - I've copied this method from MSDN by
mistake, I meant GetAllMessages method.
You should be able to use MessagePropertyFilter to fetch only IDs, which
should reduce network traffic. At least that's what .Net documentation says.

Dejan
Post by Yoel Arnon
Please note that ReceiveById simply traverses the queue serially till the
requested message, so it is not more efficient than doing this loop
yourself.
MSMQ 3.0 has ReceiveByLookupId (currently available only using the COM
interface) which is an efficient way to receive & delete a message that was
once Peeked.
How can you use GetPrivateQueuesByMachine to get a message ID?
Hope that Helps,
Yoel
www.msmq.biz
Post by Dejan Grujic
Technicaly you don't have to peek message - if you have id you can just
use ReceiveById to delete it.
However practically you got Id by peeking or by GetPrivateQueuesByMachine
or some similar method (I'm talking about doing this from .Net).
Dejan
emy
2005-02-04 05:01:42 UTC
Permalink
Post by Dejan Grujic
Good to know about how ReceiveById works. Unfortunately I can't use
ReceiveByLookupId because it's not supported from .Net 1.1.
About GetPrivateQueuesByMachine - I've copied this method from MSDN by
mistake, I meant GetAllMessages method.
You should be able to use MessagePropertyFilter to fetch only IDs, which
should reduce network traffic. At least that's what .Net documentation says.
Dejan
Post by Yoel Arnon
Please note that ReceiveById simply traverses the queue serially till the
requested message, so it is not more efficient than doing this loop
yourself.
MSMQ 3.0 has ReceiveByLookupId (currently available only using the COM
interface) which is an efficient way to receive & delete a message that was
once Peeked.
How can you use GetPrivateQueuesByMachine to get a message ID?
Hope that Helps,
Yoel
www.msmq.biz
Post by Dejan Grujic
Technicaly you don't have to peek message - if you have id you can just
use ReceiveById to delete it.
However practically you got Id by peeking or by GetPrivateQueuesByMachine
or some similar method (I'm talking about doing this from .Net).
Dejan
Hello everyone...sorry to ask again....is anyone knows why actually
the microsoft didn't provide the method to delete a specific message
in a queue.Is there any concrete reason why we are not allowed to do
so???Anyone please help me...This thing keep going on in my mind and
until now i cannot see the reason why the microsoft didn't provide
such a method.
Thanks in advance...
Doron Juster [MSFT]
2005-02-04 07:22:30 UTC
Permalink
You can definitely delete any message from a queue. You can programmatically
navigate the queue with a cursor, then receive any given message. You can
also use ReceiveByLookupID for this. (see for example
http://msdn.microsoft.com/library/en-us/msmq/msmq_about_queues_5qpf.asp).

If you use System.Messaging you can navigate a queue using
GetMessageEnumerator. Full support for cursor and lookupID will be available
in the next version of .NET framework.

I'd guess that the computer management tool cannot delete a specific message
because it's a general purpose tool, it's not designed for specific
operations which are more appropriate for an application to do. For that
reason it also does not show the complete body, just the first 260 bytes.

Thanks, Doron
--
This posting is provided "AS IS" with no warranties, and confers no rights.
.
Post by emy
Post by Dejan Grujic
Good to know about how ReceiveById works. Unfortunately I can't use
ReceiveByLookupId because it's not supported from .Net 1.1.
About GetPrivateQueuesByMachine - I've copied this method from MSDN by
mistake, I meant GetAllMessages method.
You should be able to use MessagePropertyFilter to fetch only IDs, which
should reduce network traffic. At least that's what .Net documentation says.
Dejan
Post by Yoel Arnon
Please note that ReceiveById simply traverses the queue serially till the
requested message, so it is not more efficient than doing this loop
yourself.
MSMQ 3.0 has ReceiveByLookupId (currently available only using the COM
interface) which is an efficient way to receive & delete a message that was
once Peeked.
How can you use GetPrivateQueuesByMachine to get a message ID?
Hope that Helps,
Yoel
www.msmq.biz
Post by Dejan Grujic
Technicaly you don't have to peek message - if you have id you can just
use ReceiveById to delete it.
However practically you got Id by peeking or by
GetPrivateQueuesByMachine
Post by emy
Post by Dejan Grujic
Post by Yoel Arnon
Post by Dejan Grujic
or some similar method (I'm talking about doing this from .Net).
Dejan
Hello everyone...sorry to ask again....is anyone knows why actually
the microsoft didn't provide the method to delete a specific message
in a queue.Is there any concrete reason why we are not allowed to do
so???Anyone please help me...This thing keep going on in my mind and
until now i cannot see the reason why the microsoft didn't provide
such a method.
Thanks in advance...
Frank Boyne
2005-02-05 00:32:17 UTC
Permalink
Post by emy
anyone knows why actually
the microsoft didn't provide the method to delete a
specific message
in a queue.
Partly I think the answer depends on exactly what you ean
by "a method to delete a specific message".

As Doron already posted, you can delete a message by doing
a Receive. If you are asking why there isn't a function
called MQDeleteMessage that takes similar parameters to
Receive then I'd say its because Receive already does that
and there's no need for a second function that duplicates
the capability.

On the other hand, if you are asking why there isn't an
MQDeleteMessage function with some different set of
parameters then I guess I'd ask what set of parameters you
think it would take? If those parameters are based on
message proeprties, then you have to have Peeked your way
to the message to know what those property values are, so
again receive could delete the message.

If that set of parameters were based on the contents of
the message body, then I'd say the reason there isn;t such
a function is that MSMQ itself is designed to be pretty
much ignorant of the contents of a message body - only the
sender and receiver need to know how the message body is
laid out. That's perhaps slightly less true in
SYSTEM.MESSAGING with the various formatters around, but
still it is the case that MSMQ itself doesn't look at the
body contents.

Another way of looking at this would be to say that MSMQ
is about managing queues and messages in queues and most
of the MSMQ design is focused on processing messages from
the front of the queue one at a time. Peek and cursors
etc give you some additional flexibility about how and
when you remove messages from a queue but the queue is
really still supposed to be a queue - not an arbitrary
collection of messages that can be randomly accessed and
randomly deleted.

That's my two cents worth anyway.
emy
2005-02-14 04:20:05 UTC
Permalink
Post by Frank Boyne
Post by emy
anyone knows why actually
the microsoft didn't provide the method to delete a
specific message
in a queue.
Partly I think the answer depends on exactly what you ean
by "a method to delete a specific message".
As Doron already posted, you can delete a message by doing
a Receive. If you are asking why there isn't a function
called MQDeleteMessage that takes similar parameters to
Receive then I'd say its because Receive already does that
and there's no need for a second function that duplicates
the capability.
On the other hand, if you are asking why there isn't an
MQDeleteMessage function with some different set of
parameters then I guess I'd ask what set of parameters you
think it would take? If those parameters are based on
message proeprties, then you have to have Peeked your way
to the message to know what those property values are, so
again receive could delete the message.
If that set of parameters were based on the contents of
the message body, then I'd say the reason there isn;t such
a function is that MSMQ itself is designed to be pretty
much ignorant of the contents of a message body - only the
sender and receiver need to know how the message body is
laid out. That's perhaps slightly less true in
SYSTEM.MESSAGING with the various formatters around, but
still it is the case that MSMQ itself doesn't look at the
body contents.
Another way of looking at this would be to say that MSMQ
is about managing queues and messages in queues and most
of the MSMQ design is focused on processing messages from
the front of the queue one at a time. Peek and cursors
etc give you some additional flexibility about how and
when you remove messages from a queue but the queue is
really still supposed to be a queue - not an arbitrary
collection of messages that can be randomly accessed and
randomly deleted.
That's my two cents worth anyway.
Thanks Frank...
First of all what i really mean "a method to delete a specific
message" is that a method that i can use to delete a particular
message that i choose inside a queue.Let say in Order queue, i got six
message and i want to delete the third message in that queue.How am i
supposed to do...definately not using the receive method
right??because as far as i read the receive method will only receive
the frist message inside a queue but not a particular message that we
want.Anyway thanks for your opinion.
Frank Boyne
2005-02-14 23:36:05 UTC
Permalink
Post by emy
Let say in Order queue, i got six
message and i want to delete the third message in that
queue.How am i
supposed to do...definately not using the receive method
right??
Yes, you can use Receive (well you can with some
limitations).

Using the COM interface, what you would do is use
PeekCurrent once and PeekNext twice to move down to the
third message in the queue then use ReceiveCurrent to
remove the current entry (which should now be the third
message in the queue).

Using the C++ API you'd create a cursor using
MQCreateCursor, then you'd call MQReceive message three
times, once using MQ_ACTION_PEEK_CURRENT and twice using
MQ_ACTION_PEEK_NEXT to move the cursor to the third
message in the queue. Then, you'd call MQReceiveMessage
using MQ_ACTION_RECEIVE to remove the current message from
the queue.

The limitations are that if anything happens to add or
remove messages before the intended target (another
program receiving a messsage out of the queue for example)
then the message you end up removing isn't the one that
was third in the queue when you started peeking, but some
other message that is now third in the queue. Or, if some
other process receives the message out from underneath
your cursor then the receive fails because there is no
message where the cursor says there should be one.

I don't think you can achieve the same effect using the
System.Messaging namespace though.

Loading...