Using Java in Websphere Message Broker V6.0: Creating The Code For A Javacompute Node
Using Java in Websphere Message Broker V6.0: Creating The Code For A Javacompute Node
For someone with existing Java skills the JavaCompute node can be used to code the logic of a flow wholly
using the Java language. All of this is possible from the Toolkit in an environment and deployment model that
fully supports the development process.
Once a JavaCompute node has been added to the message flow the configuration wizard must be invoked
and executed. This involves the following steps:
1. Right click on the node and select Open Java.
This action initiates the Java Compute wizard.
2. Provide a Java Project name.
This project will then be created and initialized for JavaCompute node development.
3. Provide a name for the new java class.
4. Choose a template for the node class:
a. Filtering message class, for routing within a message flow based on the contents of a
message.
b. Modifying message class, for modifying a message as it passes through the node.
c. Creating message class, for the creation of a new message which is propagated by the flow.
5. Once a template has been selected the perspective within the toolkit will be switched to the Java
perspective and code based on the selected template will be brought into focus. The logic required
by this new node can now be coded.
The following illustrates the code that is presented when the first filter template is chosen.
The content assist that is provided in Eclipse can then be used to developing the class.
Message Processing
The JavaCompute node can provide message flows with both routing and transformation logic. A summary
of the capabilities and techniques available for routing and transformation follows.
The JavaCompute node includes a two directional routing capability. The node provides this via two output
terminals which are labeled in the toolkit as the “Out” and “Alternate” terminals.
The following code extract gets these terminals so that they can be propagated to within this method. Note
the use of lower case for the initial letter when referencing the terminals within the Java code.
The following code then propagates the message received to the “Out” terminal.
out.propagate(assembly);
Similarly, to filter some messages down the alternate terminal the propagate method would be called on the
alt object. Note to immediately free the memory used by any MbMessage objects created in a node you
should always call the clearMessage method on them before returning from evaluate.
Select the Filtering Message Class template in the JavaCompute node creation wizard to create a filter type
node.
The RegexFilterNode and RoutingFileNode samples demonstrate this capability. All of the samples
referenced in this document are shipped as part of WebSphere Message Broker V6
Route to label
If routing down just two terminals is not sufficient then as within the rest of the product a Route to Label
approach can be adopted. This flow illustrates an example where the JavaCompute node determines which
label node the RouteToLabel node propagates the message to.
<document>
<chapter title='Introduction'>
Some text.
</chapter>
</document>
MbElement navigation
This Java code accesses the document and then the first chapter element in the logical tree:
MbElement root = assembly.getMessage().getRootElement();
MbElement document = root.getLastChild().getFirstChild();
MbElement chapter = document.getFirstChild(); // returns the first chapter
MbElement creation
In a similar fashion to how message tree elements can be accessed create methods are also available.
These can be used to create child and sibling elements given a particular MbElement. The following code
creates the title element as the first child of the chapter.
MbElement title = chapter.createElementAsFirstChild(MbXML.ATTRIBUTE,
"title",
"Introduction");
XPath creation
The XPath support includes XPath extensions to support creation of elements with an XPath like syntax. So
for example “/?title[set-value(‘Introduction’)]” will create a title element and set its value.
The following code given a message containing the document and chapter elements adds the title element
and sets its value:
message.evaluateXPath("/document/chapter/?@title[set-value('Introduction')]");
For the previous flow the properties can be accessed via the following Java calls:
String regexValue = (String)getUserDefinedAttribute("filterRegex");
String fieldValue = (String)getUserDefinedAttribute("filterField");
The RegexFilterNode sample demonstrates this capability and has been used for the illustrations in this
section.
Messages
Messages as they pass through a node can be used for dynamic configuration. Access to the Environment
and LocalEnvironment along with the message body provides a number of means by which this
configuration could be set. These settings could then be stored in static members of the class making the
value available to subsequent messages. Note that static variables will return to their defaults every time the
execution group is started or the message flow is deployed.
Broker attributes
The Java API provides a number of broker attributes for retrieving details of the Broker, Execution Group and
Message Flow within which the node is running. The following code retrieves the names of each of these
resources; other values not listed here are available.
String messageBrokerName = getBroker().getName();
String messageExecutionGroupName = getExecutionGroup().getName();
String messageFlowName = getMessageFlow().getName();
So again these broker attributes could be used to provide environment dependant configuration.
Files
Files on the run time system can be accessed by the Java Compute node using the standard java.io
classes these could also be used to configure the node. In addition files deployed in the jar along with the
java class files will be accessible to the java code.
Database support
Database access is available by two methods:
• MbSQLStatement – a class within the Java API which gives access to the ODBC datasources that
are managed by the broker. This is the only method of accessing a database with transactional
integrity. Updates/deletions/insertions are coordinated with the rest of the message flow.
• Type 4 JDBC drivers – Updates performed using this interface are not transactionally coordinated
with other resources which may also be update in a message flow.
Debug
Debugging the node in the Message Broker Toolkit is possible by first setting a debug port for the JVM that
the message broker is running. The following command syntax requiring the broker name, execution group
and port number is used to do this:
The execution group must be restarted for this setting to take effect. Then when setting up the message
broker debug session within the Toolkit the Java debug port should be entered.
To restart just the execution group the following command can be employed:
Sample utility methods are also included in SampleUtils.java for adding a minimal MQMD or RFH2 header.
As you can see the Java implementation compares favorably to the ESQL implementation. This is due to the
fact that as in many message brokering scenarios, including these examples, most of the processing is in the
parsing and accessing of elements within a message. This processing is performed by the same underlying
XML parser regardless of the language in which the logic is coded. Further details of the performance
improvements and the test cases used for these figures are provided in the WebSphere Message Broker
V6.0 performance reports which will be available here.
For further comparisons with the other transformation options including Mapping and XSLT, see the article
“Transformation options for WebSphere Message Broker Version 6” by Andy Piper.
z/OS users can benefit through the potential to reduce costs with the use of the JavaCompute node and the
zAAP technology. Any work done within the JavaCompute node classes will be eligible for off loading to a
zAAP processor if available. Processing costs associated with the WebSphere Message Broker message
parsers and serialization is not eligible to be run on the zAAP however.
Par files, new to version 6, provide a mechanism where by a user defined extension’s classes and
dependencies can be packaged together and installed on the broker as one unit.
Conclusion
This article has presented the extended Java support available in WebSphere Message Broker V6. Particular
focus has been given to the new JavaCompute node function in this release. It has covered the development
of the Java code for one of these nodes and the ease with which this code can now be deployed to the
broker. With both routing and transformation capabilities combined with its good performance mean that
message flows with logic coded entirely in Java become a viable alternative for those with Java skills.
Situations for which Java business logic already exists benefit from the ability to reuse this logic within one of
these nodes. The article included information on some of the additional and enhanced Java support that is
provided with this major release of the product.
To help you understand more about the Java support in WebSphere Message Broker V6 and related
technologies, links to additional resources are provided below.
Resources
• The tasks and concepts detailing the development of a JavaCompute node can be found in the
Information Center that accompanies the product and can be located by navigating to the following
headings in the table of contents:
Developing Applications Æ Developing Message Flow applications Æ Developing Java.
• IBM WebSphere MQ SupportPacs provide you with a wide range of downloadable code and
documentation that complements the WebSphere MQ family of products. Performance reports are
also available. These are available at http://www.ibm.com/software/integration/support/supportpacs/.
• Get the latest WebSphere Message Broker technical resources at the WebSphere Business
Integration zone which is available at
http://www.ibm.com/developerworks/websphere/zones/businessintegration/.
• Find out more about the IBM zSeries Application Assist Processor(zAAP) at
http://www.ibm.com/servers/eserver/zseries/zaap/ .
• Find out more about IBM Tivoli Monitor for Business Integration at
http://www.ibm.com/software/tivoli/products/monitor-integration/.