Creating JMS server, JMS module, JMS Connection Factory and JMS Queue through WLST

In this post we will see how to Creating JMS server, JMS module, JMS Connection Factory and JMS Queue using wlst scripts.

Create a directory in your system and create a properties file with below information and name it as “JMSconfig.properties“.

# 1 – ENTER Server Connection details
server.url = t3://localhost:7001
username = weblogic
password = welcome1

# 2 – ENTER JMSServer details
jms.server.name = TEST_JMSServer
store.name = TEST_JDBCStore
tragated.jms.server.name = AdminServer

# 3 – ENTER  SystemModule Details
system.module.name = TEST_JMSModule
tragated.system.module.name = AdminServer

# 4 – ENTER  ConnectionFactory Details
connection.factory.name = TEST_ConnectionFactory
connection.factory.jndi.name = jms/TEST_CF

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

# 6 – ENTER  SubDeployment & Queue Details
queue.sub.deployment.name = Sub_TEST_Queue
queue.name = TEST_Queue
queue.jndi.name = jms/TEST_Q

Now in the same directory create a new file for JMS script with below script and name it as “JMSConfig.py

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)

To use this script, we need to edit the properties file at the top of the program.

Now place both the properties and python file  in the server location(cd /your/fmwhome/wlserver/server/bin/)

Set the domain environment by running the below command.

cd /your/fmwhome/wlserver/server/bin/> setDomainEnv.cmd

Now run the python script with below command.

/your/fmwhome/wlserver/server/bin/>  java weblogic.WLST JMSConfig.py

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s