WLST script to configure JMS resources in weblogic server
A JMS queue/Topic in Weblogic Server is associated with a number of additional resources:JMS Server
A JMS server acts as a management container for resources within JMS modules. Some of its responsibilities include the maintenance of persistence and state of messages and subscribers. A JMS server is required in order to create a JMS module.
JMS Module
A JMS module is a definition which contains JMS resources such as queues and topics. A JMS module is required in order to create a JMS queue.
Subdeployment
JMS modules are targeted to one or more WLS instances or a cluster. Resources within a JMS module, such as queues and topics are also targeted to a JMS server or WLS server instances. A subdeployment is a grouping of targets. It is also known as advanced targeting.
Connection Factory
A connection factory is a resource that enables JMS clients to create connections to JMS destinations.
Persistent Store
It can be a UserDefined Persistent Store or a Default Persistent store. It is used for storing the Data (Messages).
JMS Queue/JMS Topic
JMS queue is a point-to-point destination type. A message is written to a specific queue or received from a specific queue.
JMS Topic follows Publish/Subscribe(Pub/Sub) model. Pub/sub messaging applications send and receive messages by subscribing to a topic
In this tutorial, we are going to configure JMS Queue with required additional resources through WLST script
WLST Script
The below script will help us to define the required JMS resources to enable the messaging queue
JMSConfiguration.properties
adminUserName=weblogic adminUserPassword=weblogic1 adminServerHost=localhost adminServerPort=7001fileStoreName=BAMMonitoringJMSFileStore jmsServerName=BAMMonitoringServer moduleName=BAMJMSSystemResource subDeploymentName=BAMSubdeDloyment connectionFactoryName=BAMMonitoringConnectionfactory queueName=BAMMonitoringQueue
JMSConfiguration.py
from java.io import FileInputStreampropInputStream = FileInputStream("JMSConfiguration.properties") configProps = Properties() configProps.load(propInputStream)connect(configProps.get("adminUserName"),configProps.get("adminUserPassword"), 't3://'+configProps.get("adminServerHost")+':'+configProps.get("adminServerPort"))fileStoreName=configProps.get("fileStoreName") jmsServerName=configProps.get("jmsServerName") moduleName=configProps.get("moduleName") connectionFactoryName=configProps.get("connectionFactoryName") subDeploymentName=configProps.get("subDeploymentName") queueName=configProps.get("queueName")edit() startEdit()print 'Creating File Store' cd('/') cmo.createFileStore(fileStoreName) cd('/FileStores/'+fileStoreName) cmo.setDirectory(fileStoreName) set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))print 'Creating JMS Server' cd('/') print 'Creating JMS Server.' print 'JMS Server: '+jmsServerName cmo.createJMSServer(jmsServerName) cd('/JMSServers/'+jmsServerName) cmo.setPersistentStore(getMBean('/FileStores/'+fileStoreName)) cmo.setTemporaryTemplateResource(None) cmo.setTemporaryTemplateName(None) cmo.addTarget(getMBean('/Servers/AdminServer'))print 'Creating JMS Module' cd('/') cmo.createJMSSystemResource(moduleName) cd('/JMSSystemResources/'+moduleName) cmo.addTarget(getMBean('/Servers/AdminServer')) cmo.createSubDeployment(subDeploymentName)print 'Creating Connection Factory' cd('/') cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName) cmo.createConnectionFactory(connectionFactoryName) cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/ConnectionFactories/'+connectionFactoryName) cmo.setJNDIName('jms/'+connectionFactoryName) #set('SubDeploymentName',subDeploymentName) cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/ConnectionFactories/'+connectionFactoryName+'/SecurityParams/'+connectionFactoryName) cmo.setAttachJMSXUserId(false) cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/ConnectionFactories/'+connectionFactoryName+'/ClientParams/'+connectionFactoryName) cmo.setClientIdPolicy('Restricted') cmo.setSubscriptionSharingPolicy('Exclusive') cmo.setMessagesMaximum(10) #cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/ConnectionFactories/'+connectionFactoryName+'/TransactionParams/'+connectionFactoryName) #cmo.setXAConnectionFactoryEnabled(true) cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/ConnectionFactories/'+connectionFactoryName) cmo.setDefaultTargetingEnabled(true)print 'Creating Queue' cd('/') cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName) cmo.createQueue(queueName) cd('/JMSSystemResources/'+moduleName+'/JMSResource/'+moduleName+'/Queues/'+queueName) set('JNDIName','jms/'+queueName) set('SubDeploymentName',subDeploymentName) cd('/JMSSystemResources/'+moduleName+'/SubDeployments/'+subDeploymentName) cmo.addTarget(getMBean('/JMSServers/'+jmsServerName))print 'JMS Resources are Successfully Created' activate()
Script
https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/JMSConfiguration
Before executing the script, change the configurations as required.
Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd JMSConfiguration.py
Now the required JMS resources are created and the queue is ready for messaging
The queue can be accessed using the below JNDI names
jms/BAMMonitoringConnectionfactory
jms/BAMMonitoringQueue
Nice post on JMS Resource creation.
ReplyDeleteI have just tried same but on Basic WebLogic domain by breaking the task into two parts: 1. JMSServer creation and 2. JMS Module creation.
Have a look on this.
http://wlstbyexamples.blogspot.in/2013/01/jms-configuration-using-wlst.htm