Sunday, September 2, 2012

This post explains how we can move message between JMS Queues using WLST.

In this script first we will fetch Destination JMS queue information and simply move message from Old Jms Queue to new Jms Queue.

Follow below steps to move message from one JMS Queue to another using WLST

1.) Create queue.properties file which contain all the required information. You can download file from here also.
server.url=t3://localhost:8001
username=weblogic
password=welcome1

old.server.name=soa_server1
old.jms.server=SOAJMSServer
old.jms.module=SOAJMSModule
old.queue.name=RequestQueue

new.server.name=soa_server1
new.jms.server=SOAJMSServer
new.jms.module=SOAJMSModule
new.queue.name=ResponseQueue

2.) Now create moveQueue.py file which contain WLST script which moves message from one Jms queue to another. You can download this file from here.

from java.io import FileInputStream
import java.lang
import os
import string

print 'Read Queue Property File'
Queue_PropStream = FileInputStream('queue.properties')
Queue_ConfigProp = Properties()
Queue_ConfigProp.load(Queue_PropStream)

print 'Reading Server URL property from property file'
serverUrl = Queue_ConfigProp.get('server.url')

print 'Reading Server username property from property file'
Username = Queue_ConfigProp.get('username')

print 'Reading Server password property from property file'
Password = Queue_ConfigProp.get('password')

print 'Old Queue properties'
OldServerName = Queue_ConfigProp.get('old.server.name')
OldJMSServer = Queue_ConfigProp.get('old.jms.server')
OldJMSModule = Queue_ConfigProp.get('old.jms.module')
OldQueueName = Queue_ConfigProp.get('old.queue.name')

print 'New Queue properties'
NewServerName = Queue_ConfigProp.get('new.server.name')
NewJMSServer = Queue_ConfigProp.get('new.jms.server')
NewJMSModule = Queue_ConfigProp.get('new.jms.module')
NewQueueName = Queue_ConfigProp.get('new.queue.name')

print 'connecting to server'
print 'connect('+Username+','+Password+','+serverUrl+')'

connect(Username,Password,serverUrl)

print 'server run time'
print 'serverRuntime()'
serverRuntime()

print 'get target server queue'
print 'cd(/JMSRuntime/' + NewServerName + '.jms/JMSServers/' + NewJMSServer + '/Destinations/' + NewJMSModule + '!' + NewQueueName+')'

cd('/JMSRuntime/' + NewServerName + '.jms/JMSServers/' + NewJMSServer + '/Destinations/' + NewJMSModule + '!' + NewQueueName)

print 'target=cmo.getDestinationInfo()'
target=cmo.getDestinationInfo()
print ' got the target server info'

print 'Go To Old Queue'
print 'cd(/JMSRuntime/'+OldServerName+'.jms/JMSServers/'+OldJMSServer+'/Destinations/'+OldJMSModule+'!'+OldQueueName+')'

cd('/JMSRuntime/'+OldServerName+'.jms/JMSServers/'+OldJMSServer+'/Destinations/'+OldJMSModule+'!'+OldQueueName)

print 'move queue data'
print 'cmo.moveMessages('',target)'
cmo.moveMessages('',target)
print'Message have been succesfully moved from'+OldQueueName+' to '+NewQueueName


3.) Now run above created file.

        Go To

              $MIDDLEWARE_HOME /user_projects/domains/yourdomain/bin
              $MIDDLEWARE_HOME /user_projects/domains/yourdomain/bin>setDomainEnv.cmd
              $MIDDLEWARE_HOME /user_projects/domains/yourdomain> java weblogic.WLST moveQueue.py


Note: If moveQueue.py file is not there in $MIDDLEWARE_HOME /user_projects/domains/yourdomain directory then you can simply provide full path for queueMove.py file.







0 comments :

Post a Comment