How do you handle problems when there are durable messages for a
specific client application that the client can't consume, e.g.
because the message has wrong format ?
Consuming Application (Client) should have proper exception handling
and it should throw out all bad/poison messages.
Do you have to delete all undelivered messages for this client? Or is there some tooling that can do this?
The messages will be deleted automatically by the MQ server once the
TTL (Time To Live) expires. We can't manually delete those messages as
they belong/meant for the original client (which is a durable
subscriber).
The below link explains well on the concept of JMS durable subscriptions:
https://docs.oracle.com/cd/E19798-01/821-1841/bncgd/index.html
Also I have provided the below sample code for the tool, which logs (doesn't delete) the messages from a durable subscription topic:
InitialContext ctx = new InitialContext();
Topic topic = (Topic)ctx.lookup("myJMSTopic1");
TopicConnectionFactory connFactory = (TopicConnectionFactory) ctx.lookup("topicConnFactory");
TopicConnection topicConn = connFactory.createTopicConnection();
topicConn.setClientID("myToolId1"); //Use a different client id than original subscriber
TopicSession topicSession = topicConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(topic, "myClientExistingDuraSubName"); // this is where you have to provide the original client's durable subscription name
while(true) {
Message message = topicSubscriber.receive();
TextMessage txtMsg = (TextMessage)message;
logger.info(txtMsg.getText());
}