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.
- JMSServer
- JMSModule
- Queue
- ConnectionFactory
- 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 file “domain.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 !!
Ravish Mody
November 11th, 2011 on 4:46 pm
That’s exactly what i was looking for.
Thank you so much,
Miguel
December 9th, 2011 on 11:22 pm
Thanks Ravish for excellent articles. I read some of your jms/nodemanage/clustering articles and I was trying this scenario and having problems.
My domain has a admin server and two managed servers.
admin: localhost:7001
ms1: localhost:7003
ms2: localhost:7004
ms1 and ms2 are on Machine1 and are also clustered. cluster address (localhost:7005). Node manager is properly configured and I can start/stop managed servers through console. I targetted a web app to the cluster, ms1 and ms2. Now I am having problems sending the request through the cluster. This is the url I am using: http://localhost:7005/helloapp/welcome. I can individually call http://localhost:7003/helloapp/welcome and http://localhost:7004/helloapp/welcome and that works. when creating weblogic cluster I did not have the option to give listen address or port. there was only one field cluster address and i gave value: ‘localhost:7005’ wo quotes. why am I not able connect or lookup using cluster address or how can i do that?
Jms question: for the above design, i am adding jms server to both ms1 and ms2 and targetting to the migratable target not to the cluster because it a pinned service. but then I need to target the jms module to cluster why?
Thanks lot
December 9th, 2011 on 11:54 pm
Hi weblogicjms_new,
The cluster address which you gave is wrong. Cluster Address should have the address which can be used by the clients to connect to your servers in the cluster, this address can be either a DNS host name that maps to multiple IP addresses of your managed servers or a comma separated list of single address host names or IP addresses of your managed servers. Something like shown in the below example
Cluster Address = localhost:7003,localhost:7004
Jms question: for the above design, i am adding jms server to both ms1 and ms2 and targetting to the migratable target not to the cluster because it a pinned service. but then I need to target the jms module to cluster why?
This is because both your servers are in a cluster hence it shows both managed servers under a cluster which you created, however if you check carefully you can still choose between two options which are
1) All servers in the cluster, which would automatically target your JMS module to all the managed servers which gets added/deleted in the same cluster.
2) Part of the cluster, and check which all servers you like to target your JMS module.
Regards,
Ravish Mody
December 12th, 2011 on 5:05 am
wow that was fast! thanks. i need some more clarification.
1. jms module: what is the difference between targeting the jms module just to the cluster or managed server ms1 or just to the jms server.
2. lets say we target the jms module to cluster. but then we need to target the destinations in that module through subdeployment to jms server. what is confusing is we are targetting the module to the cluster but the destinations in the module to jms server.
3.for cluster address you suggested: Cluster Address = localhost:7003,localhost:7004. a web app is deployed on cluster,ms1 and ms2. now i need to invoke the app. so how do i do it? http://localhost:7003,localhost:7004/myapp/welcome.html is giving error. i also need populate a queue using client program. t3:localhost:7003,localhost:7004 is also not working. pls suggest me something simple to test on windows. both for web app and jms client.
great work. thanks lot.
December 12th, 2011 on 5:16 pm
Hi Weblogicjms_new,
I am not sure about first two questions, But regarding your 3rd question …You can not use Comma Separated Cluster Address while using HTTP protocol ” http://localhost:7003,localhost:7004/myapp/welcome.html” (This is WRONG)
So if you want to hit the cluster using HTTP protocol then you will have to either use a Front End Proxy Server like (Apache/IIS)…etc
U can refer to the following Link: http://middlewaremagic.com/weblogic/?p=1311
You can Skip The Step8) and Step9) mentioned in the above Link.
The “httpd.conf” file settings will be like following in your case:
<IfModule mod_dir.c>
WebLogicCluster localhost:7003,localhost:7004
MatchExpression /*
</IfModule>
Rest all the Steps will be exactly same as mentioned in that Link.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma