Is there any API to delete a message from the JMS queue without using the monitoring admin tool.
Enter the username, password, and the admin server url you want to connect to. Change the location to serverRuntime by entering the command serverRuntime(). It shows all the attributes and functions of Queue1.
In the Administration Console, expand Services > Messaging > JMS Modules. In the JMS Modules table, click the JMS module that contains the configured queue that you want to access. In the selected JMS module's Summary of Resources table, click the queue that you want to monitor.
First, on your main thread you need to lock the message listener after starting your JMS connection and invoke the message listener “wait” method. On your message listener, you need to lock again the message listener and then invoke the “notify all” method. Save this answer. Show activity on this post.
I had to additionally call session.commit()
for the consumer to delete messages.
Additionally, the receivenowait
API doesn't work; call receive(1000)
instead.
Here is a working piece of code I wrote that worked on jboss
:
try {
connection = connectionFactory.createConnection();
session = connection.createSession(true,-1);
Queue queue = (Queue) QueueConnectionFactory.getInitialContext().lookup("/queue/DLQ");
QueueBrowser browser = session.createBrowser(queue);
Enumeration<?> enum1 = browser.getEnumeration();
while(enum1.hasMoreElements()) {
TextMessage msg = (TextMessage)enum1.nextElement();
MessageConsumer consumer = session.createConsumer(queue, "JMSMessageID='" + msg.getJMSMessageID() + "'");
//You can try starting the connection outside while loop as well, I think I started it inside while loop by mistake, but since this code worked I am hence letting you know what worked
connection.start();
Message message = consumer.receive(1000) ;
if ( message != null ) {
//do something with message
}
}
}
finally {
session.commit();
consumer.close();
browser.close();
session.close();
connection.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With