Weblogic WLST – Create and configure JMS Resources

WLST is a scripting tool for Weblogic AS, made by BEA (and now Oracle). It gives you a scripting interface (Jython) to manage, create and monitor Weblogic domains and instances.

In this article I will give you (and explain) a WLST script that do the followings:

  1. Load properties from file
  2. Connect to Admin Server
  3. Delete existing JMS Resources (JMS server, Filestore, JMS module)
  4. Create a Filestore and a JMS Server
  5. Create a JMS Module
  6. Create 2 JMS Queues
    1. Configure JMS Queues
    2. Set Delivery Failure
    3. Enable Logging
    4. Set Overrides properties
  7. Create an XA JMS Connection Factory

### Section 1: Load properties from file ###

You need to create a properties file (like Ant properties file). This file must be like this:

username=weblogic
password=weblogic1
providerURL=t3://localhost:7001
fileStoreDirecory=/xxx/beahome10.3.2/user_projects/domains/simple_domain/myFileStore1

Then you need the following code to read and get the properties.

def loadProperties(fileName):
	properties = Properties()
	input = FileInputStream(fileName)
	properties.load(input)
	input.close()
	result= {}
	for entry in properties.entrySet(): result[entry.key] = entry.value
	return result

properties = loadProperties("local.properties")
username = properties['username']
password = properties['password']
url = properties['providerURL']

### Section 2: Connect to Admin Server ###

connect(username, password, url)
adminServerName = cmo.adminServerName

### Section 3: Delete existing JMS Resources ###

Delete existing JMS Module

cd("/JMSSystemResources")
deleteIgnoringExceptions(moduleName)

Delete existing JMS Server and its Filestore

cd("/JMSServers")
deleteIgnoringExceptions(jmsServerName)
cd("/FileStores")
deleteIgnoringExceptions(fileStoreName)

### Section 4: Create a Filestore and a JMS Server ###

You can find this code in function createJMSServer() of the script.

# Create Filestore
cd('/')
filestore = cmo.createFileStore(fileStoreName)
filestore.setDirectory(properties['fileStoreDirecory'])
filestore.targets = (adminServer,)

cd("/JMSServers")
# Create JMS server and assign the Filestore
jmsServer = create(jmsServerName, "JMSServer")
jmsServer.setPersistentStore(filestore)
jmsServer.targets = (adminServer,)

### Section 5: Create a JMS Module ###

The code creates a JMS Module and a Subdeployment for this dodule. You can find this code in function createJMSModule() inside the script.

cd('/JMSSystemResources')
jmsModule = create(moduleName, "JMSSystemResource")
jmsModule.targets = (adminServer,)

cd(jmsModule.name)
# Create and configure JMS Subdeployment for this JMS System Module
sd = create(subDeploymentName, "SubDeployment")
myJMSServer = getMBean('/JMSServers/' + jmsServerName)
sd.targets = (myJMSServer,)

### Section 6 & 7 ###

At these steps we create 2 JMS Queues (myRequestQueueEDQ, myRequestQueue).
The ‘myRequestQueueEDQ’ is used as Failed destination delivery queue for the ‘myRequestQueue’, which our application request queue. When redelivery limit of a JMS Message is exceeded (this is a Weblogic feature, but you can find it to other AS too), then you can configure messaging system to redirect this message to another queue (other actions are: Log and Reject). This is an extremely useful feature, and the ‘myRequestQueueEDQ’ is used to named as Dead Letter Queue.
In order to use this feature, we MUST set the ‘Redelivery Limit’ for this queue, because by default is to ‘-1’ (for ever).
Code also sets the ‘Redelivery Delay Override’ parameter, which is the delay that a failed message will be again available to consumers.
Also, code enables Logging of JMS Properties and set Delivery mode to ‘Persistent’ to always persist the messages.
You can find the related code at functions createDLQ() and createQueue().

### Section 8: Create an XA JMS Connection Factory ###

The code to do this is the following and you can find it inside the script in function createCF().

cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName)
cf = create(cfname, "ConnectionFactory")
cf.JNDIName = cfjndiname
cf.subDeploymentName = subDeploymentName
# Set XA transactions enabled
cf.transactionParams.setXAConnectionFactoryEnabled(1)

### RUN ###

Before run the script you need the followings:

  1. Create the directory for the JMS Filestore.
  2. A running Weblogic instance.
  3. Set the local.properties values according to this Weblogic instance

The final step is to start WLST and execute/interpret the script. This can be done with a Bash shell like this:

cd WL_HOME/server/bin
source setWLSEnv.sh
cd ~/develop/wlst
java weblogic.WLST createConfigureJMSResources.py

### Useful data ###

  1. The WLST script: createConfigureJMSResources.py
  2. The properties file: local.properties
  3. Script has been tested with Weblogic 10.3.2 and 10.3.3
  4. OS was GNU/Linux Debian Lenny

This is the simplest use of WLST. WLST has many useful features that can save you much time. I will try to post more articles with other features of WLST.

Regards,
Adrianos.

Democracy requires Free Software.

NOTES:
# You are free do modify and distribute this script as you like.
# This script is for Weblogic WLST, which is a proprietary product of Oracle.
# Please use JBoss AS if it is possible, as it is as good as Weblogic and the source code is available.

Advertisement

About Adrianos Dadis

Building Big Data & Stream processing solutions in many business domains. Interested in distributed systems and enterprise integration.
This entry was posted in Administration, Weblogic and tagged , , . Bookmark the permalink.

Post your thought

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 )

Facebook photo

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

Connecting to %s