You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by girish lc <gi...@gmail.com> on 2017/05/24 05:52:04 UTC

delete message from Queue through Java code

Hi Team,

I need help in deleting the message from the Queue in Qpid through Java
code.


Current status:

I am sending the messages to the Qpid Queue using JMS and from the Queue
I'm reading the messages through read module and now I need to delete the
particular message from the Queue based on some event. May I have any code
or API for this.

-- 
Regards,
Girish LC
#09886521716

Re: delete message from Queue through Java code

Posted by Rob Godfrey <ro...@gmail.com>.
On 24 May 2017 at 11:57, girishlc <gi...@gmail.com> wrote:

> Rob,
>
> 1. When you talk about Queue Browsing, is it QueueBrowser class you are
> talking ?
>

Yes


> 2. I'm using Qpid Broker for Java with its in-built web console, where I
> can
> see the message status "Available" to "Acquired" after reading the message
> from Client.
> 3. I am receiving the acknowledgment from the consumer, able to send that
> acknowledgment to Qpid. From that Qpid is able to remove the message but
> there is no mapping between the messages acknowledged and removed. I want
> to
> map the acknowledgment based on the MessagID. Is there any method to get
> the
> messageID for the delivered message.
>
>
The behaviour of acknowledge is defined by JMS, it is not specific to
Qpid.  From
https://docs.oracle.com/javaee/7/api/javax/jms/Message.html#acknowledge-- :

"Acknowledges all consumed messages of the session of this consumed message.

All consumed JMS messages support the acknowledge method for use when a
client has specified that its JMS session's consumed messages are to be
explicitly acknowledged. By invoking acknowledge on a consumed message, a
client acknowledges all messages consumed by the session that the message
was delivered to."

I think everyone agrees it would be a lot less confusing if the
acknowledge() method was on the Session object (since it really operates
against the whole Session, not the particular message you call it on).
Unfortunately JMS defines the behaviour and places the method on the
Message.

JMS does not define a mechanism to acknowledge individual messages.

-- Rob


> --girish
>
>
>
> --
> View this message in context: http://qpid.2158936.n2.nabble.
> com/Re-delete-message-from-Queue-through-Java-code-tp7663338p7663354.html
> Sent from the Apache Qpid developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
> For additional commands, e-mail: dev-help@qpid.apache.org
>
>

Re: delete message from Queue through Java code

Posted by girishlc <gi...@gmail.com>.
For example,

I have 10 messages read from Queue, and 4th and 6th messages are not
delivered. Then ultimately except 4th and 6th messages all other messages to
be removed from the Queue.

Now, In my code 
1. How can I differentiate the acknowledge for each message.
2. Is it sequential that I will get the ack in the same order in the Queue ?
Queue Message:    1,     2,      3,     4,           5,     6,           7,     
8,     9,      10
Ack                :    ack1, ack2, ack3, negack4, ack5, negack6, ack7,
ack8, ack9, ack10
3. I think it will not be sequential (priority queue), how should I hold the
ack for perticular message and process other messages ?



--
View this message in context: http://qpid.2158936.n2.nabble.com/Re-delete-message-from-Queue-through-Java-code-tp7663338p7663397.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Re: delete message from Queue through Java code

Posted by girishlc <gi...@gmail.com>.
Rob,

1. When you talk about Queue Browsing, is it QueueBrowser class you are
talking ?
2. I'm using Qpid Broker for Java with its in-built web console, where I can
see the message status "Available" to "Acquired" after reading the message
from Client.
3. I am receiving the acknowledgment from the consumer, able to send that
acknowledgment to Qpid. From that Qpid is able to remove the message but
there is no mapping between the messages acknowledged and removed. I want to
map the acknowledgment based on the MessagID. Is there any method to get the
messageID for the delivered message.

--girish



--
View this message in context: http://qpid.2158936.n2.nabble.com/Re-delete-message-from-Queue-through-Java-code-tp7663338p7663354.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Re: delete message from Queue through Java code

Posted by Rob Godfrey <ro...@gmail.com>.
On 24 May 2017 at 08:45, girishlc <gi...@gmail.com> wrote:

> Hi Gordon,
>
> Thanks for the reply,
>
> >>Generally, messages are removed from the queue once they have been
> >>acknowledged by the consuming client. The default in JMS is (I believe)
> >>auto-acknowledge, so when your message listener's onMessage() returns,
> >>the library will automatically acknowledge the queue.
>
> 1. Actually what if some other client also wants to read that message ?
>

When using JMS consumers against a queue it is defined that only one
consumer will get the message.  The only way to read messages from a queue
while allowing other clients to also read the same message from the same
queue is to use Queue Browsing



> 2. Is there any setting that we need to do at Qpid WebManagement portal ?
>     I can see the status of the message changes from "Available" to
> "Acquired" after reading the message from Client, but how to remove this
> from the Queue.
>

Just for clarity, when you say the Qpid Web Management portal, which
product are you describing - are you using the Qpid Broker for Java with
its built in web console, or a different broker / web management console?


> 3. Is there any method to delete the message based on the "Message Id"
>

JMS does not really have a concept of "deleting" a message.  One approach
(and not a particularly nice one) is (presuming that you have used a queue
browser initially) to create a new consumer for the queue with a selector
based on the JMSMessageID.  Since the JMSMessageID is unique then that
consumer should bring back one message (if the message has not already been
deleted), or zero messages if it has been deleted.

In general I'd try to avoid this pattern though as it requires creating a
new consumer for each message, then closing it again, which is not very
efficient.

-- Rob


>
> >>I'm not sure what you mean by 'read module' though. Are you using JMS to
> >>consume messages? Or some other API
>     I'm using JMS in that I've created the new module called read module
> which reads the message from Qpid.
>
>
>
>
>
> --
> View this message in context: http://qpid.2158936.n2.nabble.
> com/Re-delete-message-from-Queue-through-Java-code-tp7663338p7663340.html
> Sent from the Apache Qpid developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
> For additional commands, e-mail: dev-help@qpid.apache.org
>
>

Re: delete message from Queue through Java code

Posted by Gordon Sim <gs...@redhat.com>.
On 24/05/17 08:45, girishlc wrote:
> Hi Gordon,
>
> Thanks for the reply,
>
>>> Generally, messages are removed from the queue once they have been
>>> acknowledged by the consuming client. The default in JMS is (I believe)
>>> auto-acknowledge, so when your message listener's onMessage() returns,
>>> the library will automatically acknowledge the queue.
>
> 1. Actually what if some other client also wants to read that message ?

If you want to view messages without consuming them, you should use the 
QueueBrowser part of the API.

> 2. Is there any setting that we need to do at Qpid WebManagement portal ?
>     I can see the status of the message changes from "Available" to
> "Acquired" after reading the message from Client, but how to remove this
> from the Queue.

When the consuming client acknowledges the acquired message, it should 
be removed.

> 3. Is there any method to delete the message based on the "Message Id"

Not directly, no. You could consume using a selector the picks a 
particular message id. That is not terribly efficient though as it's not 
really the mode of operation brokers were designed for.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Re: delete message from Queue through Java code

Posted by girishlc <gi...@gmail.com>.
Hi Gordon,

Thanks for the reply,

>>Generally, messages are removed from the queue once they have been 
>>acknowledged by the consuming client. The default in JMS is (I believe) 
>>auto-acknowledge, so when your message listener's onMessage() returns, 
>>the library will automatically acknowledge the queue. 

1. Actually what if some other client also wants to read that message ?
2. Is there any setting that we need to do at Qpid WebManagement portal ?
    I can see the status of the message changes from "Available" to
"Acquired" after reading the message from Client, but how to remove this
from the Queue.
3. Is there any method to delete the message based on the "Message Id"

>>I'm not sure what you mean by 'read module' though. Are you using JMS to 
>>consume messages? Or some other API
    I'm using JMS in that I've created the new module called read module
which reads the message from Qpid.





--
View this message in context: http://qpid.2158936.n2.nabble.com/Re-delete-message-from-Queue-through-Java-code-tp7663338p7663340.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Re: delete message from Queue through Java code

Posted by Gordon Sim <gs...@redhat.com>.
On 24/05/17 06:52, girish lc wrote:
> Hi Team,
>
> I need help in deleting the message from the Queue in Qpid through Java
> code.
>
>
> Current status:
>
> I am sending the messages to the Qpid Queue using JMS and from the Queue
> I'm reading the messages through read module and now I need to delete the
> particular message from the Queue based on some event. May I have any code
> or API for this.

Generally, messages are removed from the queue once they have been 
acknowledged by the consuming client. The default in JMS is (I believe) 
auto-acknowledge, so when your message listener's onMessage() returns, 
the library will automatically acknowledge the queue.

I'm not sure what you mean by 'read module' though. Are you using JMS to 
consume messages? Or some other API?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org