Use WLST to Delete All JMS Messages From a Destination

I got a question today about whether WebLogic Server has any tools to delete all messages from a JMS Queue.  It just so happens that the WLS Console has this capability already.  It’s available on the screen after the “Show Messages” button is clicked on a destination’s Monitoring tab as seen in the screen shot below.

deleteJMS

The console is great for something ad-hoc, but what if I want to automate this?  Well it just so happens that the console is just a weblogic application layered on top of the JMX Management interface.  If you look at the MBean Reference, you’ll find a JMSDestinationRuntimeMBean that includes the operation deleteMessages that takes a JMS Message Selector as an argument.  If you pass an empty string, that is essentially a wild card that matches all messages.

Coding a stand-alone JMX client for this is kind of lame, so let’s do something more suitable to scripting.  In addition to the console, WebLogic Scripting Tool (WLST) based on Jython is another way to browse and invoke MBeans, so an equivalent interactive shell session to delete messages from a destination would looks like this:

D:\Oracle\fmw11gr1ps3\user_projects\domains\hotspot_domain\bin>setDomainEnv.cmd

D:\Oracle\fmw11gr1ps3\user_projects\domains\hotspot_domain>java weblogic.WLST

 

Initializing WebLogic Scripting Tool (WLST) ...

 

Welcome to WebLogic Server Administration Scripting Shell

 

Type help() for help on available commands

 

wls:/offline> connect('weblogic','welcome1','t3://localhost:7001')

Connecting to t3://localhost:7001 with userid weblogic ...

Successfully connected to Admin Server 'AdminServer' that belongs to domain 'hotspot_domain'.

 

Warning: An insecure protocol was used to connect to the

server. To ensure on-the-wire security, the SSL port or

Admin port should be used instead.

 

wls:/hotspot_domain/serverConfig> serverRuntime()

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.

For more help, use help(serverRuntime)

 

wls:/hotspot_domain/serverRuntime> cd('JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0')

wls:/hotspot_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> ls()

dr--   DurableSubscribers

 

-r--   BytesCurrentCount                            0

-r--   BytesHighCount                               174620

-r--   BytesPendingCount                            0

-r--   BytesReceivedCount                           253548

-r--   BytesThresholdTime                           0

-r--   ConsumersCurrentCount                        0

-r--   ConsumersHighCount                           0

-r--   ConsumersTotalCount                          0

-r--   ConsumptionPaused                            false

-r--   ConsumptionPausedState                       Consumption-Enabled

-r--   DestinationInfo                              javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=DestinationInfo,items=((itemName=ApplicationName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),(itemName=ModuleName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),(itemName

openmbean.SimpleType(name=java.lang.Boolean)),(itemName=SerializedDestination,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),(itemName=ServerName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),(itemName=Topic,itemType=javax.management.openmbean.SimpleType(name=java.lang.Boolean)),(itemName=VersionNumber,itemType=javax.management.op

ule-0!Queue-0, Queue=true, SerializedDestination=rO0ABXNyACN3ZWJsb2dpYy5qbXMuY29tbW9uLkRlc3RpbmF0aW9uSW1wbFSmyJ1qZfv8DAAAeHB3kLZBABZTeXN0ZW1Nb2R1bGUtMCFRdWV1ZS0wAAtKTVNTZXJ2ZXItMAAOU3lzdGVtTW9kdWxlLTABAANBbGwCAlb6IS6T5qL/AAAACgEAC0FkbWluU2VydmVyAC2EGgJW+iEuk+ai/wAAAAsBAAtBZG1pblNlcnZlcgAthBoAAQAQX1dMU19BZG1pblNlcnZlcng=, ServerName=JMSServer-0, Topic=false, VersionNumber=1})

-r--   DestinationType                              Queue

-r--   DurableSubscribers                           null

-r--   InsertionPaused                              false

-r--   InsertionPausedState                         Insertion-Enabled

-r--   MessagesCurrentCount                         0

-r--   MessagesDeletedCurrentCount                  3

-r--   MessagesHighCount                            2

-r--   MessagesMovedCurrentCount                    0

-r--   MessagesPendingCount                         0

-r--   MessagesReceivedCount                        3

-r--   MessagesThresholdTime                        0

-r--   Name                                         SystemModule-0!Queue-0

-r--   Paused                                       false

-r--   ProductionPaused                             false

-r--   ProductionPausedState                        Production-Enabled

-r--   State                                        advertised_in_cluster_jndi

-r--   Type                                         JMSDestinationRuntime

 

-r-x   closeCursor                                  Void : String(cursorHandle)

-r-x   deleteMessages                               Integer : String(selector)

-r-x   getCursorEndPosition                         Long : String(cursorHandle)

-r-x   getCursorSize                                Long : String(cursorHandle)

-r-x   getCursorStartPosition                       Long : String(cursorHandle)

-r-x   getItems                                     javax.management.openmbean.CompositeData[] : String(cursorHandle),Long(start),Integer(count)

-r-x   getMessage                                   javax.management.openmbean.CompositeData : String(cursorHandle),Long(messageHandle)

-r-x   getMessage                                   javax.management.openmbean.CompositeData : String(cursorHandle),String(messageID)

-r-x   getMessage                                   javax.management.openmbean.CompositeData : String(messageID)

-r-x   getMessages                                  String : String(selector),Integer(timeout)

-r-x   getMessages                                  String : String(selector),Integer(timeout),Integer(state)

-r-x   getNext                                      javax.management.openmbean.CompositeData[] : String(cursorHandle),Integer(count)

-r-x   getPrevious                                  javax.management.openmbean.CompositeData[] : String(cursorHandle),Integer(count)

-r-x   importMessages                               Void : javax.management.openmbean.CompositeData[],Boolean(replaceOnly)

-r-x   moveMessages                                 Integer : String(java.lang.String),javax.management.openmbean.CompositeData,Integer(java.lang.Integer)

-r-x   moveMessages                                 Integer : String(selector),javax.management.openmbean.CompositeData

-r-x   pause                                        Void :

-r-x   pauseConsumption                             Void :

-r-x   pauseInsertion                               Void :

-r-x   pauseProduction                              Void :

-r-x   preDeregister                                Void :

-r-x   resume                                       Void :

-r-x   resumeConsumption                            Void :

-r-x   resumeInsertion                              Void :

-r-x   resumeProduction                             Void :

-r-x   sort                                         Long : String(cursorHandle),Long(start),String[](fields),Boolean[](ascending)

 

wls:/hotspot_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> cmo.deleteMessages('')

2


where the domain name is “hotspot_domain”, the JMS Server name is “JMSServer-0”, the Queue name is “Queue-0” and the System Module is named “SystemModule-0”.  To invoke the operation, I use the “cmo” object, which is the “Current Management Object” that represents the currently navigated to MBean.  The 2 indicates that two messages were deleted. 

Combining this WLST code with a recent post by my colleague Steve that shows you how to use an encrypted file to store the authentication credentials, you could easily turn this into a secure automated script.  If you need help with that step, a long while back I blogged about some WLST basics.  Happy scripting.

Comments:

Hi James, Is there any WSLT script where i can list all the JMS Messages targetted to Weblogic Managed Node not admin server? Any help is much appreciated. Thanks, Sunil Nandargi

Posted by Sunil on April 18, 2011 at 08:06 AM PDT #

Sunil, JMS Servers targeted at WLS servers manage the queues/topics. You should be able to invoke operations from the AdminServer that affect Managed Servers or connect directly to the server. I sent you a more thorough example in email. Thanks, James

Posted by james.bayer on April 18, 2011 at 03:00 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

James Bayer Image
I was formerly a Product Manager on the WebLogic Server team based out of Oracle HQ. You can find my new blog at http://iamjambay.com.
Follow Me on Twitter
Oracle WebLogic

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today