JMS

Setup JMS with Unit-Of-Order using WLST

Ravish Mody

Yesterday one of our subscribers Miguel had asked us using comment how to configure the Unit-of-Order property using WLST script, as he was already able to create a JMSServer, JMSModule and JMS Connection Factory using a wlst script but was having an issue setting the  Unit-of-Order property, hence it seemed to be a great topic to create an article on it. With below single script you can create and target following components.

  1. JMSServer
  2. JMSModule
  3. Queue
  4. ConnectionFactory
  5. Unit-Of-Order

As usual we have used a properties file which has all the required details in it like the JMSServer, JMSModule, Queue, ConnectionFactory names, targets name etc. This way you would not have to modify anything in your actual WLST script.

Setup JMS with Unit-Of-Order using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLSTJMS

Step2). Write a Properties filedomain.properties inside “C:WLSTJMS” like following:

# 1 - Connecting details
server.url = t3://localhost:7001
username = weblogic
password = weblogic

# 2 - JMSServer details
jms.server.name = My_JMSServer
store.name = MyJDBCStore
tragated.jms.server.name = AdminServer

# 3 - SystemModule Details
system.module.name = My_SystemModule
tragated.system.module.name = AdminServer

# 4 - ConnectionFactory Details
connection.factory.name = My_ConnectionFactory
connection.factory.jndi.name = My_CF

# 5 - Unit Of Order Details
unit.of.order.value = 1

# 6 - SubDeployment & Queue Details
queue.sub.deployment.name = Sub_My_Queue
queue.name = My_Queue
queue.jndi.name = My_Q

Step2). Now in the same directory write the following WLST Script “JMS_Setup.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################

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

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

# 1 - Connecting details
serverUrl = configProps.get("server.url")
Username = configProps.get("username")
Password = configProps.get("password")

# 2 - JMSServer details
jmsServerName = configProps.get("jms.server.name")
storeName = configProps.get("store.name")
tragatedJMSServerName = configProps.get("tragated.jms.server.name")

# 3 - SystemModule Details
systemModuleName = configProps.get("system.module.name")
tragatedSystemModuleName = configProps.get("tragated.system.module.name")

# 4 - ConnectionFactory Details
connectionFactoryName = configProps.get("connection.factory.name")
ConnectionFactoryJNDIName = configProps.get("connection.factory.jndi.name")

# 5 - Unit Of Order Details
unitOfOrderValue = configProps.get("unit.of.order.value")

# 6 - SubDeployment & Queue Details
queueSubDeploymentName = configProps.get("queue.sub.deployment.name")
queueName = configProps.get("queue.name")
queueJNDIName = configProps.get("queue.jndi.name")

redirect('wlst.log','false')

# 1 - Connecting to the Destination 
connect(Username,Password,serverUrl)

edit()

# 2 - JMSServer details
print "================== JMSSever ==================="
startEdit()
cmo.createJMSServer(jmsServerName)
print "Created a JMSServer !!"
cd('/Deployments/'+jmsServerName)
cmo.setPersistentStore(getMBean('/JDBCStores/'+storeName))
print "PersistentStore has been set for the JMSServer !!"
set('Targets',jarray.array([ObjectName('com.bea:Name='+tragatedJMSServerName+',Type=Server')], ObjectName))
print "Targeted the JMSServer !!"
activate()
print ""

# 3 - SystemModule Details
print "================== SystemModule ==================="
startEdit()
cd('/')
cmo.createJMSSystemResource(systemModuleName)
print "Created a SystemModule !!"
cd('/SystemResources/'+systemModuleName)
set('Targets',jarray.array([ObjectName('com.bea:Name='+tragatedSystemModuleName+',Type=Server')], ObjectName))
print "Targeted the SystemModule !!"
activate()
print ""

# 4 - ConnectionFactory Details
print "================== ConnectionFactory ==================="
startEdit()
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName)
cmo.createConnectionFactory(connectionFactoryName)
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName)
cmo.setJNDIName(ConnectionFactoryJNDIName)
print "Created a ConnectionFactory !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName+'/SecurityParams/'+connectionFactoryName)
cmo.setAttachJMSXUserId(false)
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName)
cmo.setDefaultTargetingEnabled(true)
print "Targeted the ConnectionFactory !!"
activate()
print ""

# 5 - Unit Of Order Details
print "================== Unit Of Order ==================="
startEdit()
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName+'/DefaultDeliveryParams/'+connectionFactoryName)
cmo.setDefaultUnitOfOrder(unitOfOrderValue)
print "Changed Unit Of Order !!"
activate()
print ""

# 6 - SubDeployment & Queue Details
print "================== SubDeployment & Queue ==================="
startEdit()
cd('/SystemResources/'+systemModuleName)
cmo.createSubDeployment(queueSubDeploymentName)
print "Created a SubDeployment for Queue !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName)
cmo.createQueue(queueName)
print "Created a Queue !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/Queues/'+queueName)
cmo.setJNDIName(queueJNDIName)
cmo.setSubDeploymentName(queueSubDeploymentName)
cd('/SystemResources/'+systemModuleName+'/SubDeployments/'+queueSubDeploymentName)
set('Targets',jarray.array([ObjectName('com.bea:Name='+jmsServerName+',Type=JMSServer')], ObjectName))
print "Targeted the Queue to the created subdeployment !!"
activate()
print ""

cmd = "rm -f wlst.log"
os.system(cmd)

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST JMS_Setup.py

Following would be the Output

java weblogic.WLST JMS_Setup.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands


================== JMSSever ===================
Created a JMSServer !!
PersistentStore has been set for the JMSServer !!
Targeted the JMSServer !!

================== SystemModule ===================
Created a SystemModule !!
Targeted the SystemModule !!

================== ConnectionFactory ===================
Created a ConnectionFactory !!
Targeted the ConnectionFactory !!

================== Unit Of Order ===================
Changed Unit Of Order !!

================== SubDeployment & Queue ===================
Created a SubDeployment for Queue !!
Created a Queue !!
Targeted the Queue to the created subdeployment !!

Regards,

Ravish Mody


[Updated Version] Steps to Move Messages From One Queue To Another Queue Using WLST

Ravish Mody

Today one of our subscribers Pavan had  come back saying that the WLST script which was created by us previously How to Move Messages From One Queue To Another Queue Using WLST was only “working to move the messages from one queue to another queue which are on the same servers only”  by using comment , and as per his requirement they need to move the messages from Queue-1 to Queue-2 which are targeted to Server-1 and Server-2 respectively. Hence I have just made few modification in my previous script and thus this is the update version of it

I had to add two URL’s to get connected to the with the respective servers and also added two System Module this way you can move the messages from any Source Server to the Destination Server which can be in the same module or if the destination server is in different system module too this way its more flexible. All this can be done using the same script just give the domain and there servers details in the domain.properties files and you are good to go.

[Updated Version] Steps to Move Messages From One Queue To Another Queue Using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLSTMove_Messages”

Step2). Write a Properties filedomain.properties inside “C:WLSTMove_Messages” like following:

######################
#    Destination
######################
new.server.url=t3://localhost:8003
new.system.module.name=SystemModule2
new.tragated.server.name=MS-2
new.jms.server.name=JMSServer2
new.queue.name=Q2

######################
#	Source
######################
old.server.url=t3://localhost:8002
old.system.module.name=SystemModule1
old.tragated.server.name=MS-1
old.jms.server.name=JMSServer1
old.queue.name=Q1

username=weblogic
password=weblogic

Step2). Now in the same directory write the following WLST Script “move_messages.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

newserverUrl = configProps.get("new.server.url")
newsystemModuleName = configProps.get("new.system.module.name")
newTragatedServerName = configProps.get("new.tragated.server.name")
newJmsServerName = configProps.get("new.jms.server.name")
newQueueName = configProps.get("new.queue.name")

oldserverUrl = configProps.get("old.server.url")
oldsystemModuleName = configProps.get("old.system.module.name")
oldTragatedServerName = configProps.get("old.tragated.server.name")
oldJmsServerName = configProps.get("old.jms.server.name")
oldQueueName = configProps.get("old.queue.name")

Username = configProps.get("username")
Password = configProps.get("password")

# Connecting to the Destination
connect(Username,Password,newserverUrl)
serverRuntime()

print 'Getting the traget...'
cd('/JMSRuntime/'+newTragatedServerName+'.jms/JMSServers/'+newJmsServerName+'/Destinations/'+newsystemModuleName +'!'+ newQueueName)
target = cmo.getDestinationInfo()
print 'Got the traget...'

disconnect()
print ''

# Connecting to the Source
connect(Username,Password,oldserverUrl)
serverRuntime()
cd('/JMSRuntime/'+oldTragatedServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+oldsystemModuleName +'!'+ oldQueueName)

print 'Moving the messages to the new traget...'
cmo.moveMessages('',target)
print 'Messages have been moved to the traget Successfully !!!'

print '===================================================================================='
print 'Messages from queue: "'+oldQueueName+'" have been moved to the new queue: "'+newQueueName+'" Successfully !!!'
print '===================================================================================='

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST move_messages.py

Following would be the Output

java weblogic.WLST move_messages.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:8003 with userid weblogic ...
Successfully connected to managed Server 'MS-2' that belongs to domain 'Domain_8001'.

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.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

Getting the traget...
Got the traget...
Disconnected from weblogic server: MS-2

Connecting to t3://localhost:8002 with userid weblogic ...
Successfully connected to managed Server 'MS-1' that belongs to domain 'Domain_8001'.

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.

Moving the messages to the new traget...
Messages have been moved to the traget Successfully !!!
====================================================================================
Messages from queue: "Q1" have been moved to the new queue: "Q2" Successfully !!!
====================================================================================

Note:

Pava you would have to change the line number – 35  & 45 as per your environment

Regards,
Ravish Mody


How to Move Messages From One Queue To Another Queue Using WLST

Ravish Mody

Two days back one of our subscribers Pavan had asked us by using comment , that is it possible to move the messages from one queue to another queue that to using WLST and the answer to that question is YES. It is possible to do the same using WLST and we have created the WLST script.

This is a very simple script which would just collect the target/destination queue where the messages has to be moved to (i.e. new.queue.name) and then would just go to the queue where the messages has to be moved from(i.e. old.queue.name). All this can be done using the same script just give the domain and there servers details in the domain.properties files and you are good to go.

Steps to Move Messages From One Queue To Another Queue Using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLSTMove_Messages”

Step2). Write a Properties filedomain.properties inside “C:WLSTMove_Messages” like following:

server.url=t3://localhost:8001
username=weblogic
password=weblogic

system.module.name=MySystemModule

old.server.name=AdminServer
old.jms.server.name=Admin_JMSServer
old.queue.name=Admin_Queue

new.tragated.server.name=AdminServer
new.jms.server.name=MyJMSServer
new.queue.name=MyTestQueue

Step2). Now in the same directory write the following WLST Script “move_messages.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

serverUrl = configProps.get("server.url")
Username = configProps.get("username")
Password = configProps.get("password")

systemModuleName = configProps.get("system.module.name")

oldServerName = configProps.get("old.server.name")
oldJmsServerName = configProps.get("old.jms.server.name")
oldQueueName = configProps.get("old.queue.name")

newTragatedServerName = configProps.get("new.tragated.server.name")
newJmsServerName = configProps.get("new.jms.server.name")
newQueueName = configProps.get("new.queue.name")

connect(Username,Password,serverUrl)

serverRuntime()

print 'Getting the traget...'
cd('/JMSRuntime/'+newTragatedServerName+'.jms/JMSServers/'+newJmsServerName+'/Destinations/'+systemModuleName +'!'+ newQueueName)
target = cmo.getDestinationInfo()
print 'Got the traget...'

cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+ oldQueueName)

print 'Moving the messages to the new traget...'
cmo.moveMessages('',target)
print 'Messages have been moved to the traget Successfully !!!'

print '======================================='
print 'Messages from queue: "'+oldQueueName+'" have been moved to the new queue: "'+newQueueName+'" Successfully !!!'
print '======================================='

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST move_messages.py

Following would be the Output

java weblogic.WLST move_messages.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:8001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_8001'.

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.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

Getting the traget...
Got the traget...
Moving the messages to the new traget...
Messages have been moved to the traget Successfully !!!
=======================================
Messages from queue: "Admin_Queue" have been moved to the new queue: "MyTestQueue" Successfully !!!
=======================================

Note:

Only for Pava you would have to do the following changes
– Instead for line number – 34
cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+newJmsServerName+'@'+ newQueueName)
- Instead for line number - 38
cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+oldJmsServerName+'@'+ oldQueueName)

Regards, Ravish Mody


Copyright © 2010-2012 Middleware Magic. All rights reserved. |