Tuesday, March 12, 2013

Creating Foreign JMS Server configurations through WLST script in Weblogic server

Creating Foreign JMS Server configurations through WLST script in Weblogic server


WebLogic JMS enables you to reference foreign (that is, external) JMS providers within a local WebLogic JNDI tree. Using the Foreign JMS Server node, you can quickly map a foreign JMS provider so that its connection factories and destinations appear in the WebLogic JNDI tree as a local JMS objects.

A Foreign JMS Server configuration can also be used to reference remote instances of WebLogic Server in another cluster or domain in the local WebLogic JNDI tree

Once the Foreign Provider is configured within Weblogic, for all practical purposes within the code — it can be called as if it was on local JNDI lookup. Weblogic will make the remote calls transparent to your code. This allows you to change your destination via configuration on the Weblogic console.

This tutorial explains the approach to configure Foreign JMS server through WLST script
WLST Script

The below WLST script help us to create a Foreign JMS server in a local server for a JMS resources running in a remote weblogic server(in different domain) but the same can be used to configure Foreign Server with external providers .

The JMS Server running on t3://localhost:7002 is configured as a Foreign JMS Server for t3://localhost:7002

The JMS clients can use the local JNDI configured in the local server to send the messages to the remote JMS server.

The same script can be modified to create a Foreign JNDI Server for other JMS providers, some of the important remote server properties to be modified is remoteDestinationJNDI, remoteConnectionFactoryJNDI, remoteConnectionURL, initialJNDIContextFactory, remoteUserName and remotePassword

ConfigureForeignJMSServer.properties

adminUserName=weblogic
adminUserPassword=weblogic1
adminServerHost=localhost
adminServerPort=7001foreignJMSModuleName=BAMForeginJMSResource
foreignJMSServerName=BAMForeignJMSServer
localConnectionFactoryJNDI=jms/BAMMonitoringConnectionfactory1
remoteConnectionFactoryJNDI=jms/BAMMonitoringConnectionfactory1
localDestinationJNDI=jms/BAMMonitoringQueue1
remoteDestinationJNDI=jms/BAMMonitoringQueue1remoteConnectionURL=t3://localhost:7002
initialJNDIContextFactory= weblogic.jndi.WLInitialContextFactory
remoteUserName=weblogic
remotePassword=welcome1

ConfigureForeignJMSServer.py

from java.io import FileInputStreampropInputStream = FileInputStream("ConfigureForeignJMSServer.properties")
configProps = Properties()
configProps.load(propInputStream)connect(configProps.get("adminUserName"),configProps.get("adminUserPassword"), 't3://'+configProps.get("adminServerHost")+':'+configProps.get("adminServerPort"))foreignJMSModuleName=configProps.get("foreignJMSModuleName")
foreignJMSServerName=configProps.get("foreignJMSServerName")
localConnectionFactoryJNDI=configProps.get("localConnectionFactoryJNDI")
localDestinationJNDI=configProps.get("localDestinationJNDI")remoteDestinationJNDI=configProps.get("remoteDestinationJNDI")
remoteConnectionFactoryJNDI=configProps.get("remoteConnectionFactoryJNDI")remoteConnectionURL=configProps.get("remoteConnectionURL")
initialJNDIContextFactory=configProps.get("initialJNDIContextFactory")
remoteUserName=configProps.get("remoteUserName")
remotePassword=configProps.get("remotePassword")edit()
startEdit()cd('/')
cmo.createJMSSystemResource(foreignJMSModuleName)cd('/SystemResources/'+foreignJMSModuleName)
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName)
cmo.createForeignServer(foreignJMSServerName)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)
cmo.setDefaultTargetingEnabled(true)cmo.setJNDIPropertiesCredential(remotePassword)cmo.setInitialContextFactory(initialJNDIContextFactory)
cmo.setConnectionURL(remoteConnectionURL)
cmo.createJNDIProperty('java.naming.security.principal')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/JNDIProperties/java.naming.security.principal')
cmo.setValue(remoteUserName)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)cmo.createForeignConnectionFactory('ForeignJMSConnectionFactory')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/ForeignConnectionFactories/ForeignJMSConnectionFactory')
cmo.setLocalJNDIName(localConnectionFactoryJNDI)
cmo.setRemoteJNDIName(remoteConnectionFactoryJNDI)cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName)
cmo.createForeignDestination('ForeignJMSDestination')cd('/JMSSystemResources/'+foreignJMSModuleName+'/JMSResource/'+foreignJMSModuleName+'/ForeignServers/'+foreignJMSServerName+'/ForeignDestinations/ForeignJMSDestination')
cmo.setLocalJNDIName(localDestinationJNDI)
cmo.setRemoteJNDIName(remoteDestinationJNDI)activate()

Script

https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/ConfigureForeignJMSServer

Before executing the script, change the configurations as required.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd ConfigureForeignJMSServer.py







Now the foreign JMS server is configured and ready for use — the messages can be send/receive through local JNDI’s , Weblogic server internally communicate to the remote server. The foreign JMS server configuration helps as to abstract the remote server details from clients, the remote server implementations can be changed any time without impacting the clients

Monday, March 11, 2013

Creating JMS Adapter connection factory through WLST script in weblogic server

Creating JMS Adapter connection factory through WLST script in weblogic server:

The below WLST script will help us to create the JMS adapter connection factories. Before Executing the script change the details accordingly.

configureJMSAdapterConnection.py

TargetServerName='AdminServer'

soaHome='oracle/Middleware/Oracle_SOA1'

appPathJms=soaHome+'/soa/connectors/JmsAdapter.rar'
appNameJms='JmsAdapter'
moduleOverrideNameJms=appNameJms+'.rar'
JMSJNDIName = 'eis/wls/BAMQueueConnection'
JMSConnectionfactory='jms/BAMMonitoringConnectionfactory'
#Sever Details

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathJms=soaHome+'/soa/connectors/Plan_JMS.xml'

def createJMSConnectionFactory():

        edit()
        startEdit()
        startApplication(appNameJms)
        myPlanJms=loadApplication(appPathJms, planPathJms)
        makeDeploymentPlanVariable(myPlanJms,'ConnectionInstance_eis/Jms_JNDIName_13102979357209', JMSJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="'+JMSJNDIName+'"]/jndi-name',moduleOverrideNameJms)
        makeDeploymentPlanVariable(myPlanJms, 'ConfigProperty_eis/JMS_JNDIName_ConnectionFactory_Name_13102979357210', JMSConnectionfactory,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="'+JMSJNDIName+'"]/connection-properties/properties/property/[name="ConnectionFactoryLocation"]/value',moduleOverrideNameJms)

        myPlanJms.save();
        save();
        cd('/AppDeployments/JmsAdapter/Targets');
        updateApplication(appNameJms, planPathJms);
        activate(block='true');
     
  
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       adminURL='t3://localhost:9001'
       adminUserName='weblogic'
       adminPassword='welcome1'
       connect(adminUserName, adminPassword, adminURL)
       createJMSConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd configureJMSAdapterConnection.py

Monday, March 4, 2013

WLST script to configure JMS resources in weblogic server

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=7001
JMSConfiguration.py
from java.io import FileInputStream


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