Tuesday, September 27, 2011

WLST move JMS messages

Thanks to our friends of MiddleWare Magic:

http://middlewaremagic.com/weblogic/?p=6765

that I will never praise enough...



connect('weblogic', 'welcome1', 't3://pierrepc:7011')
easeSyntax()
serverRuntime()
cd('/JMSRuntime/ms1.jms/JMSServers/jmsserver1/Destinations/MS1SystemModule!Q2')
q2 = cmo
cd('/JMSRuntime/ms1.jms/JMSServers/jmsserver1/Destinations/MS1SystemModule!Q1')
q1 = cmo
#THIS WILL MOVE MESSAGES
q1.moveMessages('', q2.getDestinationInfo())

To move messages in small chunks, rather than all in a go:

from weblogic.jms.extensions import JMSMessageInfo
connect('weblogic', 'weblogic1', 't3://acme.com:10001')  
easeSyntax()
serverRuntime()

chunkSize = 25

cd /JMSRuntime/osbpl1ms1.jms/JMSServers/CommonJmsServer1/Destinations/GM_StockDownloadJMSModule!CommonJmsServer1@StockDownloadReprocessQ
sourceQueue = cmo
cd /JMSRuntime/osbpl1ms1.jms/JMSServers/CommonJmsServer1/Destinations/GM_StockDownloadJMSModule!CommonJmsServer1@StockDownloadQ
destinationQueue = cmo

sourceCursor = sourceQueue.getMessages('', 0)
sourceCursorSize = sourceQueue.getCursorSize(sourceCursor)
print "there are", sourceCursorSize, "in source"

sourceMessages = sourceQueue.getNext(sourceCursor, chunkSize )

if sourceMessages != None:
    for message in sourceMessages:
        msgwithbody = JMSMessageInfo(message)
        messageId = msgwithbody.getMessage().getJMSMessageID()
        print 'Message ID           - ' + messageId
        sourceQueue.moveMessages("JMSMessageID='" + messageId + "'", destinationQueue.getDestinationInfo())



Additional useful code:

#move messages to destination
sourceQueue.moveMessages('', destinationQueue.getDestinationInfo())

#send them back to origin
destinationQueue.moveMessages('', sourceQueue.getDestinationInfo())

Move a message based on a Selector messageId = "some id":

sourceQueue.moveMessages("JMSMessageID='ID:<64972.1369647706567.0>'", destinationQueue.getDestinationInfo()) Funnily, if I run:

destinationQueue.importMessages(sourceMessages, True) I get an error message:

importMessages operation not supported with replaceOnly=true

See also http://weblogicserver.blogspot.com/2010/07/using-wlst-script-to-list-messages-from.html?_sm_au_=iVVmZBV2WBRm0Dfr for excellent coding examples.

3 comments:

Unknown said...

Hi,

when I use cmo.getMessages('',0) I get the below error:

wls:/PRD_RD/serverRuntime/JMSRuntime/wls_server1.jms/JMSServers/DXService_JMSServer/Destinations/DX_SystemModule!AD_STORE> cursor = cmo.getMessages('',0)
Traceback (innermost last):
File "", line 1, in ?
java.lang.UnsupportedOperationException: getMessages(String, Integer) not valid for class weblogic.jms.backend.BEDestinationRuntimeMBeanImpl
at weblogic.jms.backend.BEMessageManagementRuntimeDelegate.getMessages(BEMessageManagementRuntimeDelegate.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at weblogic.management.jmx.modelmbean.WLSModelMBean.invoke(WLSModelMBean.java:437)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$16.run(WLSMBeanServerInterceptorBase.java:449)
at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.invoke(WLSMBeanServerInterceptorBase.java:447)
at weblogic.management.mbeanservers.internal.JMXContextInterceptor.invoke(JMXContextInterceptor.java:263)
at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$16.run(WLSMBeanServerInterceptorBase.java:449)
at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.invoke(WLSMBeanServerInterceptorBase.java:447)
at weblogic.management.mbeanservers.internal.SecurityInterceptor.invoke(SecurityInterceptor.java:444)
at weblogic.management.jmx.mbeanserver.WLSMBeanServer.invoke(WLSMBeanServer.java:323)
at weblogic.management.mbeanservers.internal.JMXConnectorSubjectForwarder$11$1.run(JMXConnectorSubjectForwarder.java:663)
at weblogic.management.mbeanservers.internal.JMXConnectorSubjectForwarder$11.run(JMXConnectorSubjectForwarder.java:661)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.management.mbeanservers.internal.JMXConnectorSubjectForwarder.invoke(JMXConnectorSubjectForwarder.java:654)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1427)
at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1367)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
at javax.management.remote.rmi.RMIConnectionImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:668)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:518)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:119)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

san said...

Hello
Thanks for script, I am getting below error could you please let me know how to resolve.
Issue is at line 8 not at line 24...

Getting the traget...
No stack trace available.
Problem invoking WLST - Traceback (innermost last):
File "/opt/oracle/fmw_12_2_1_2_0/wlserver/server/bin/moveQueuemessages.py", line 8, in ?
File "", line 168, in cd
File "", line 553, in raiseWLSTException
WLSTException: Error cding to the MBean

Thanks in advance

vernetto said...

san, the best thing is to execute manually, line by line, the script, and interactively examine your MBean tree using ls() . Probably you are using a different name for the JMS server or other resources...