Monday, November 3, 2014

Creating JMS Resources iteratively using Maven and WLST script in 12c

In the previous post we have seen how to create a JMSSserver and JMSModule using WLST.

To extent this script further, with multiple sets of JMSServer and JMSModules we can follow the below approach


Create jms.properties file for each set of configuration.

Please note use the convention as jms1, jms2,jms3 for the properties files

===========jms1.properties=================
domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer1
jms.jmssystemresource=TEST_JMSSystemResource1
jms.subdeployment=TEST_JMSSubdeployment1
jms.queue=TEST_JMSQUEUE1
jms.queue.jndi=jms/TEST_JMSQUEUE1
jms.topic=TEST_JMSTOPIC1
jms.topic.jndi=jms/TEST_JMSTOPIC1
jms.targetserver=DefaultServer

============end of properties================



===========jms2.properties=================

domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer2
jms.jmssystemresource=TEST_JMSSystemResource2
jms.subdeployment=TEST_JMSSubdeployment2
jms.queue=TEST_JMSQUEUE2
jms.queue.jndi=jms/TEST_JMSQUEUE2
jms.topic=TEST_JMSTOPIC2
jms.topic.jndi=jms/TEST_JMSTOPIC2
jms.targetserver=DefaultServer




============end of properties================

Save the following python script as jmsobjects.py

================start of python script============

 from java.io import FileInputStream

for i in 1,2:

  
    propInputStream = FileInputStream("path\\to\\jms"+str(i)+".properties")
    configProps = Properties()
    configProps.load(propInputStream)

    domainName=configProps.get("domain.name")
  
    adminURL=configProps.get("admin.url")
    adminUserName=configProps.get("admin.userName")
    adminPassword=configProps.get("admin.password")

    jms_server=configProps.get("jms.jmsserver")
    print 'jms_server : '+jms_server
    jms_systemResource=configProps.get("jms.jmssystemresource")
    print 'jms_systemResource : '+jms_systemResource
    jms_queue=configProps.get("jms.queue")
    print 'jms_queue : '+jms_queue
    jms_queue_jndi=configProps.get("jms.queue.jndi")
    print 'jms_queue_jndi : '+jms_queue_jndi
    jms_subdeployment=configProps.get("jms.subdeployment")
    print 'jms_subdeployment : '+jms_subdeployment
    jms_topic=configProps.get("jms.topic")
    print 'jms_topic : '+jms_topic
    jms_topic_jndi=configProps.get("jms.topic.jndi")
    print 'jms_topic_jndi :'+jms_topic_jndi
    jms_targetserver=configProps.get("jms.targetserver")
    print 'jms_targetserver : '+jms_targetserver


    #connect('weblogic','weblogic1', 't3://localhost:7101')
    connect(adminUserName, adminPassword, adminURL)

    # Creating a JMS Server

    edit()
    startEdit()
    cd('/')
    print 'Creating JMS Server.'
    cmo.createJMSServer(jms_server)
    cd('/JMSServers/'+jms_server)
    cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
    activate()

    # Creating a Module

    startEdit()
    cd('/')
    cmo.createJMSSystemResource(jms_systemResource)
    cd('/JMSSystemResources/'+jms_systemResource)
    cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
    cmo.createSubDeployment(jms_subdeployment)
    activate()

    # Creating Queue

    startEdit()
    print 'Creating Queue & Topic '
    cd('/')
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
    cmo.createQueue(jms_queue)
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Queues/'+jms_queue)
    set('JNDIName',jms_queue_jndi)
    set('SubDeploymentName',jms_subdeployment)
    cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
    cmo.addTarget(getMBean('/JMSServers/'+jms_server))
    activate()

    # Creating Topic

    startEdit()
    cd('/')
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
    cmo.createTopic(jms_topic)
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Topics/'+jms_topic)
    set('JNDIName',jms_topic_jndi)
    set('SubDeploymentName',jms_subdeployment)
    cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
    set('Targets',jarray.array([ObjectName('com.bea:Name='+jms_server+',Type=JMSServer')],ObjectName))
 
    
activate()
   

=================end of python script===========

Now open command prompt
Execute the following command after correcting the path as per your soa installation
mvn wls:wlst -DfileName=path/to/jmsobjects.py  - DmiddlewareHome=path/to/oraclehome 
-DdomainHome=path/to/domainhome

No comments:

Post a Comment