Question

I want to delete all the messages in a queue configured in Websphere 8.5 SIB. Below are two approaches I tried, but none of them seem to be working and each throws a different exception. Can someone please advise on what is the correct way to achieve this.

Approach 1

MBeanServerConnection connection = getServerConnection();
connection.invoke(new ObjectName("WebSphere:*,type=SIBQueuePoint,name=jms.queue.MY_QUEUE"), "deleteAllQueuedMessages", null, null);

This approach throws the below exception.

javax.management.InstanceNotFoundException: WebSphere:type=SIBQueuePoint,name=jms.queue.MY_QUEUE

Approach 2

MBeanServerConnection connection = getServerConnection();
ObjectName objQueue = new ObjectName(WAS85_RESOURCE_URL + ",type=SIBQueuePoint");
Set<ObjectName> objNames = connection.queryNames(objQueue, null);
for(ObjectName objName: objNames) {
    String qName = connection.getAttribute(objName,"identifier").toString();
    if(qName.equals("jms.queue.MY_QUEUE")) {
        connection.invoke(objName, "deleteAllQueuedMessages", null, null);
    }
}

This approach throws the below exception.

javax.management.ReflectionException: Target method not found: com.ibm.ws.sib.admin.impl.JsQueuePoint.deleteAllQueuedMessages

Was it helpful?

Solution

Figured out the issue.

The 2nd approach works. The issue was with my invocation of the deleteAllQueuedMessages message. The method takes a boolean argument which indicates the messages should be moved to the Exception Destination. I was not passing this argument !!!

I corrected the implementation as below and it works now.

connection.invoke(objName, "deleteAllQueuedMessages", new Object[]{false}, new String[]{"java.lang.Boolean"});

OTHER TIPS

A better way to delete all Messages is something like that:

String queryString = "WebSphere:*,type=JMSAdministration";
        ObjectName queryServer = new ObjectName(queryString);
        String serverStr = "";

        Set pet = aClient.queryNames(queryServer, null);

        Iterator itsServer = pet.iterator();

        if (itsServer.hasNext())
            serverStr = itsServer.next().toString();

        ObjectName obj = new ObjectName(serverStr);

        Object param[] = { "jms/messageQueue","jms/messageCF" };
        String signature[] = { "java.lang.String","java.lang.String" };

        aClient.invoke(obj, "clear", param, signature);

Using MBean JMSAdministration is better because you can set Query exacly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top