For AQ JMS Weblogic integration, our documents were based on Weblogic admin console. While the admin console is more user friendly because of its intuitive and easy GUI interface, it is less desirable for some situations such as following comparing with WLST.
1) The configuration is huge with hundreds of connection factories and destinations
2) The same configuration need to be done repeatedly many times
3) The User wants to keep an easy to read record of what have been configured
The difficulty of directly using the WLST is to understand and navigate the complex structure of WebLogic management. In this blog, we demonstrate a jython script to help to overcome this difficulty.
The script is structured into several jython functions so it can be easily customized by other people. Here is the list of functions
def createDataSource(host, port, sid, username=”, password=”, \
dsName=DEFAULT_DATASOURCE_NAME, \
dsJndiName=DEFAULT_DATASOURCE_JNDI, xa=DEFAULT_DATASOURCE_XA, \
serverTargets=DEFAULT_DATASOURCE_SERVER_TARGETS, \
clusterTargets=DEFAULT_DATASOURCE_CLUSTER_TARGETS):
This function creates a Weblogic datasource for AQJMS usage
host: the host name of the Oracle database
port: the port number of the Oracle database
sid: the SID of the Oracle database
username: the Oracle database username
password: the Oracle database password
dsName: the name of the datasource, the default is ‘aqds’
dsJndiName: the JNDI name of the datasource, the default is ‘jdbc/aqds’
xa: whether to use the XA driver or non-XA driver
serverTargets: the server targets of this datasource in a comma separated string
the default is ‘AdminServer’
clusterTargets: the cluster targets of this datasource in a comma separated string
the default is empty string
This function will ask for Oracle database username and password dynamically
if they are not passed by parameters
def createAQModule(aqcfs, aqdests, \
moduleName=DEFAULT_AQ_MODULE_NAME, \
fsName=DEFAULT_AQ_FS_NAME, \
dsJndiName=DEFAULT_DATASOURCE_JNDI, \
serverTargets=DEFAULT_AQ_MODULE_SERVER_TARGETS,\
clusterTargets=DEFAULT_AQ_MODULE_CLUSTER_TARGETS):
This function creates an AQ module in Weblogic Server
aqcfs: A sequence of connection factories data of this AQ foreign server
aqdests: A sequence of destinations data of this AQ foreign server
moduleName: the name of this AQ module, the default is ‘aq_module’
fsName: the name of the AQ foreign server, the default is ‘aq_fs’
dsJndiName: the JNDI name of the Weblogic datasource of this AQ foreign server,
the default is ‘jdbc/aqds’
serverTargets: the server targets of this AQ module in a comma separated string
the default is ”AdminServer’
clusterTargets: the cluster targets of this AQ module in a comma separated string
the default is empty string
def setupAQJMSFromFile(filepath):
This function parses the configuration file and setup AQ module and datasource in
Weblogic with the data in the configuration file. The configuration file is in key=value
format.
The list of mandatory keys are listed below
HOST: the host of AQ server
PORT: the port of AQ server
SID: the database sid of AQ server
USERNAME: the database username of AQ server
PASSWORD: the database password of AQ server
The list of optional keys are listed below
CONN_FACT: the data to create a Weblogic foreign server connection factory
pointing to an AQ JMS connection factory. The value of this property is as
following:
{WLS_CF_NAME:
,CF_JNDI:
,CF_TYPE:
}
where the CF_TYPE has to be one of ‘ConnectionFactory’,
‘QueueConnectionFactory’, ‘TopicConnectionFactory’, ‘XAConnectionFactory’
‘XAQueueConnectionFactory’ and ‘XATopicConnectionFactory’
DESTINATION: the data to create a Webloic foreign server destination pointing to an
AQ destination. The value of this property is as following:
{WLS_DEST_NAME:
,AQ_DEST_NAME:
,DEST_JNDI:
,DEST_TYPE:
}
where the DEST_TYPE has to be either ‘QUEUE’ or ‘TOPIC’
DATASOURCE_NAME: the name of the datasource, default to ‘aqds’
DATASOURCE_JNDI: the JNDI name of the datasource, default to ‘jdbc/aqds’
DATASOURCE_XA: whether the datasource uses XA driver, default to 1
DATASOURCE_SERVER_TARGETS: the server targets of this datasource in a
comma separated string. default to ‘AdminServer’
DATASOURCE_CLUSTER_TARGETS: the cluster targets of this datasource in a
comma separated string. default to empty string
AQ_MODULE_NAME: the Weblogic module for AQJMS, default to ‘aq_module’
AQ_FS_NAME: the Weblogic foreign server name for AQJMS, default to ‘aq_fs’
AQ_MODULE_SERVER_TARGETS: the server targets of this aq module in a comma
separated string. default to ‘AdminServer’
AQ_MODULE_CLUSTER_TARGETS: the cluster targets of this aq module in a
comma separated string. default to empty string
When the script is run, it will ask the user for a configuration file and call ‘setupAQJMSFromFile’ with this file. Most configuration parameters in this script have default value except the most essential ones such as database host, port, sid, connection factory info and destination info. The script also does a best effort validation of these data.
Here are some examples of using this script.
1) Running the script standalone
java weblogic.WLST aq_wlst.py
with the AQ configuration file as following:
HOST=localhost
PORT=5521
SID=db11
USERNAME=jmsuser
PASSWORD=jmsuser
CONN_FACT=WLS_CF_NAME:aqcf,CF_JNDI:aqcf,CF_TYPE:XAQueueConnectionFactory}
DESTINATION=WLS_DEST_NAME:aq_queue,AQ_DEST_NAME:MY_QUEUE,DEST_JNDI:aq_queue,DEST_TYPE:QUEUE}
DATASOURCE_SERVER_TARGETS=ms1,ms2
DATASOURCE_CLUSTER_TARGETS=Cluster-0
AQ_MODULE_SERVER_TARGETS=ms1,ms2
AQ_MODULE_CLUSTER_TARGETS=Cluster-0
After it runs, the datasource, AQ module, AQ foreign server, connection factories and destinations will be configured and targeted. The datasource name, datasource JNDI name, AQ module name, AQ foreign server name are not provided in the configuration file, so the script uses the default value as above.
2) Running the script to execute multiple AQ configuration files in one transaction
The script is structured into several functions so it is easy to customize or extend. For example, here is an example extension. We can modify the main function of the script to get all the files with the extension conf in the current directory and execute them in one transaction instead of asking for configuration file from the user.
import glob
connect()
failed=1
try:
edit()
startEdit()
for cf in glob.glob("*.conf"):
setupAQJMSFromFile(cf)
activate(200000, block='true')
failed=0
finally:
if failed:
undo('false','y')
disconnect('true')
The script and a sample configuration file are attached with this blog. aq_wlst.py myconfig