Thursday, 12 March 2009

Create a JDBC connection in Websphere Message Broker

To get access to a transactional and pooled (?) data source from a Websphere message broker Java computer node, you will need to register a configurable service first.

Example of registrating a JDBC Oracle Server

set BROKERNAME=BRK_MYNAME
set PROVIDERNAME=OracleNAME

echo delete %PROVIDERNAME%
mqsideleteconfigurableservice %BROKERNAME% -c JDBCProviders -o %PROVIDERNAME%

echo create %PROVIDERNAME%
mqsicreateconfigurableservice %BROKERNAME% -c JDBCProviders -o %PROVIDERNAME% -n connectionUrlFormat,connectionUrlFormatAttr1,databaseName,databaseType,databaseVersion,jarsURL,portNumber,securityIdentity,serverName,type4DatasourceClassName,type4DriverClassName -v "jdbc:oracle:thin:[user]/[password]@//[serverName]:[portNumber]/[connectionUrlFormatAttr1]","XXXXX","XXXXX","Oracle","10.2","C:\oracle\Ora\jdbc\lib","1521","SXX","hostname.domain.se","oracle.jdbc.xa.client.OracleXADataSource","oracle.jdbc.OracleDriver"

echo stop broker
mqsistop %BROKERNAME%

echo setup user and password for %PROVIDERNAME%
mqsisetdbparms %BROKERNAME% -n jdbc::SXX -u user -p pass

echo start broker
mqsistart %BROKERNAME%

echo report properties
mqsireportproperties %BROKERNAME% -c JDBCProviders -o OracleNAME -r

After the configurable service has been created, you can retrive the Oracle connection with the getJDBCType4Connection as such:

String connectionName = "OracleNAME";
Connection conn = null;

conn = getJDBCType4Connection(connectionName,MbNode.JDBC_TransactionType.MB_TRANSACTION_AUTO);

Because the broker is managing the connections, your code may not:
  • perform any action that COMMITs or a ROLLBACKs the database transaction.
  • closes the connection to the database.
For more information and restrictions, refer to the WMB documentation,section Interacting with databases using the JavaCompute node

WESB Dynamic service gateway

The top new feature in Websphere ESB 6.2 that I have found is the support for Dynamic service gateways. This enables one to create a single instance that handles multiple protocols, multiple servuces and threat them the same, e.g. a simple way to create a single flow that handles multiple services and does the same VETRO pattern regardless of protocol.

The following image illustrates a flow that handles different protocols in the same way.



So far this has been hard to implement in IBMs Websphere Message Broker and Websphere ESB.

For example, in Messagebroker (6.1) the SOAP nodes binds to a single WSDL and in Websphere ESB the SCA components are also staticaly bound to a implementation. So far the easiest way of doing this has been to use a generic type with subtypes and example of this is the Salesforce.com Enterprise API where one operation supports multiple business objects.

See the IBM documentation for more information / examples.

Wednesday, 4 February 2009

IAM3: WebSphere Message Broker - Log4j Node

New support pack for using Log4j within the broker.

Thursday, 18 September 2008

Example using the MacroDefs ibmwmqcreateBar

So how do we use the ibmwmqcreateBar macrodef I listed in the last post?

It is simle as the macrodef defines a task named ibmwmqcreateBar that can be used like any other task.

Here is an example call:

<property name="ibmmqsicommon.location" location="ibmmqsicommon.xml"/>
<import file="${ibmmqsicommon.location}"/>


<path id="files.path">
<fileset dir="${esbtempbuild.dir}/">
<include name="**/MasterFlow*.msgflow"/>
<include name="**/Niceflow.msgflow"/>
</fileset>
</path>

<property name="included_projects" value="Flows CommonJava JavaFlows CommonESQL"/>

<pathconvert property="string.files.path" refid="files.path" pathsep=" ">
<map from="${tempbuild.dir}/" to=""/>
</pathconvert>

<pathconvert property="string.classpath.path" refid="classpath.path" pathsep=";"/>

<ibmwmqcreateBar workspacedirectory="${esbtempbuild.dir}"
barfilename="${bar.file}"
projectnames="${included_projects}"
filepaths="${string.files.path}"
classpath="${string.classpath.path}"/>

Macrodef and WebSphere Message Broker and Ant deployment scripting

Ant Macrodefs may be of great use in your WMB build process. Macrodefs are a new feature in Ant 1.6 toghether with and . Read more about thease new tasks in New Ant 1.6 Features for Big Projects

WMB does not expose any Java API for bulding bar files so one has to use the executables that is installed with the Broker Toolkit. The broker toolkit is only avalaible on Windows and Linux as of today.

The following is a listing is an example of macrodef wrappers for buildbar, deploybar and changebar, which are the most commonly used build tools.


<?xml version="1.0"?>
<project name="ibmmqsicommon">

<macrodef name="ibmwmqcreateBar">
<attribute name="workspacedirectory"/>
<attribute name="barfilename"/>
<attribute name="projectnames"/>
<attribute name="filepaths"/>
<attribute name="classpath"/>
<sequential>
<echo level="debug" message="[ibmwmqcreateBar] enter"/>

<echo level="info" message="[ibmwmqcreateBar] Create @{barfilename} "/>
<fail message="[ibmwmqcreateBar] barfilename needs to be set.">
<condition>
<equals arg1="@{barfilename}" arg2="" />
</condition>
</fail>

<dirname property="barfilname.dir" file="@{barfilename}"/>

<mkdir dir="${barfilname.dir}"/>

<delete file="@{barfilename}"/>

<echo level="debug" message="[ibmwmqcreateBar] run exec two times since mqsicreatebar most often fails the first time" />

<available file="${toolkit.home}/mqsicreatebar.exe" property="mqsicreatebar.present"/>

<fail unless="mqsicreatebar.present" message="[ibmwmqcreateBar] ${toolkit.home}/mqsicreatebar.exe not found check build.properties"/>

<echo level="info">[ibmwmqcreateBar] Calling mqsicreatebar, this may take several minutes </echo>
<exec dir="@{workspacedirectory}"
executable="${toolkit.home}/mqsicreatebar.exe"
spawn="false"
newenvironment="false"
searchpath="true"
failonerror="false"
vmlauncher="false"
resultproperty="exec.returnvalue"
logError="true"
output="@{barfilename}tmp.log"
error="@{barfilename}_err.tmp.log">
<env key="CLASSPATH" value="@{classpath}"/>
<arg value="-data"/>
<arg value="@{workspacedirectory}"/>
<arg value="-b"/>
<arg value="@{barfilename}.temp"/>
<arg line="-p @{projectnames}"/>
<arg line="-o @{filepaths}"/>
</exec>

<echo level="info">[ibmwmqcreateBar] Calling mqsicreatebar, this may take several minutes </echo>
<exec dir="@{workspacedirectory}"
executable="${toolkit.home}/mqsicreatebar.exe"
spawn="false"
newenvironment="false"
searchpath="true"
failonerror="false"
vmlauncher="false"
resultproperty="exec.returnvalue"
logError="true"
output="@{barfilename}.log"
error="@{barfilename}_err.log">
<env key="CLASSPATH" value="@{classpath}"/>
<arg value="-cleanBuild "/>
<arg value="-data"/>
<arg value="@{workspacedirectory}"/>
<arg value="-b"/>
<arg value="@{barfilename}"/>
<arg line="-p @{projectnames}"/>
<arg line="-o @{filepaths}"/>
</exec>

<echo level="info">[ibmwmqcreateBar] mqsicreatebar return value ${exec.returnvalue} </echo>
<fail message="[ibmwmqcreateBar] Bar Creation failed, check logs in @{barfilename} directory ">
<condition>
<not>
<equals arg1="${exec.returnvalue}" arg2="2"/>
</not>
</condition>
</fail>
<echo level="info" message="[ibmwmqcreateBar] ibmwmqcreateBar successful"/>
<echo level="debug" message="[ibmwmqcreateBar] leave"/>
</sequential>
</macrodef>

<macrodef name="ibmwmqdeployBAR">
<attribute name="inbrokername"/>
<attribute name="inipname"/>
<attribute name="inportname"/>
<attribute name="inqmname"/>
<attribute name="inbarfile"/>
<attribute name="inexegrpname"/>
<sequential>
<echo level="debug" message="[ibmwmqdeployBAR] enter"/>

<echo level="info" message="[ibmwmqdeployBAR] Deploy @{inbarfile} "/>
<echo level="info" message="[ibmwmqdeployBAR] Deploy to @{inqmname}:@{inbrokername}:@{inexegrpname} (@{inipname}:@{inportname}) "/>

<available file="${mqsi.home}/bin/mqsideploy.bat" property="mqsideploy.present"/>

<fail unless="mqsideploy.present" message="[ibmwmqdeployBAR] ${mqsi.home}/bin/mqsideploy.bat not found check build.properties"/>

<exec executable="${mqsi.home}/bin/mqsideploy.bat"
spawn="false"
resultproperty="exec.returnvalue" >
<arg value="-b"/>
<arg value="@{inbrokername}"/>
<arg value="-i"/>
<arg value="@{inipname}"/>
<arg value="-p"/>
<arg value="@{inportname}"/>
<arg value="-q"/>
<arg value="@{inqmname}"/>
<arg value="-bar"/>
<arg value="@{inbarfile}"/>
<arg value="-e"/>
<arg value="@{inexegrpname}"/>
</exec>

<echo level="info">[ibmwmqdeployBAR] mqsicreatebar return value ${exec.returnvalue} </echo>
<fail message="[ibmwmqdeployBAR] Bar deploy failed ">
<condition>
<not>
<equals arg1="${exec.returnvalue}" arg2="0"/>
</not>
</condition>
</fail>
<echo level="info" message="[ibmwmqdeployBAR] ibmwmqdeployBAR successful"/>
<echo level="debug" message="[ibmwmqdeployBAR] leave"/>
</sequential>
</macrodef>

<macrodef name="ibmwmqmodifyBAR">
<attribute name="inbarname"/>
<attribute name="inbarpropertiesname"/>
<sequential>
<echo level="debug" message="[ibmwmqmodifyBAR] enter"/>
<echo level="info" message="[ibmwmqmodifyBAR] Applying overrides in Broker Archive file - @{inbarname}" />
<echo level="info" message="[ibmwmqmodifyBAR] Using properties from @{inbarpropertiesname}" />
<echo level="debug"
message="[ibmwmqmodifyBAR] mqsiapplybaroverride.exe
-b @{inbarname} -p @{inbarpropertiesname}" />

<available file="${toolkit.home}/mqsiapplybaroverride.exe" property="mqsiapplybaroverride.present"/>

<fail unless="mqsiapplybaroverride.present" message="[ibmwmqmodifyBAR] ${toolkit.home}/mqsiapplybaroverride.exe not found check build.properties"/>

<exec executable="${toolkit.home}/mqsiapplybaroverride.exe"
resultproperty="exec.returnvalue"
spawn="false">
<arg value="-b" />
<arg value="@{inbarname}" />
<arg value="-p" />
<arg value="@{inbarpropertiesname}" />
</exec>

<echo level="info">[ibmwmqmodifyBAR] mqsiapplybaroverride return value ${exec.returnvalue} </echo>
<fail message="[ibmwmqmodifyBAR] Bar modify failed ">
<condition>
<not>
<equals arg1="${exec.returnvalue}" arg2="2"/>
</not>
</condition>
</fail>

<echo level="info" message="[ibmwmqmodifyBAR] Completed apply overrides in Broker Archive file - @{inbarname}" />
<echo level="debug" message="[ibmwmqmodifyBAR] leave"/>
</sequential>
</macrodef>

</project>


References:
[1] WebSphere Message Broker deployment scripting using Ant