Documente Academic
Documente Profesional
Documente Cultură
30 Jul 2003
Companies today have business software on disparate systems. For example, the
human resource system might be on a Sun Solaris server, a customer relationship
management system might be on Windows, and financials might be on the
mainframe. Companies have a need to connect these systems, and developing the
middleware to connect these systems is expensive. WebSphere MQ can connect all
your business software to form one efficient enterprise. All this integration is based
on two actions: putting messages on queues and reading them off of queues. In this
tutorial, you'll learn how to perform these tasks using a Domino database and the
Java platform. These simple examples will open a wide vista of integration options to
you.
Section 1. Introduction
This tutorial discusses how you can integrate Lotus Domino with WebSphere MQ
using LotusScript and the Java platform. We'll set up two forms in Lotus Domino for
use by a Lotus Notes client -- one to put a message to, and the other to get a
message from, WebSphere MQ. Then we'll set up two more forms for the Web to do
the same thing. We could have created just two forms -- one for the Notes client and
the other for the browser client -- but by proceeding in this way, we'll see two
different ways to use the Java platform within Domino. Finally, we'll set up a Domino
Java scheduled agent that will execute every hour to see if there are any messages
on a particular queue.
Companies today have business software on disparate systems. For example, the
human resources system might be on a Sun Solaris server, a customer relationship
management system might be on Microsoft Windows, and financials might be on a
mainframe. Companies have a need to connect these systems, and developing the
middleware to connect these systems is expensive. WebSphere MQ can connect all
your business software to form one efficient enterprise. WebSphere MQ minimizes
time taken to integrate applications on different systems, so your company can
respond quickly to new market strategies. While the examples we're using here may
seem simple, many of WebSphere MQ's integration functions are based on two
actions: putting messages on queues and reading them off of queues. Once you've
learned a few simple ways to achieve these tasks with Domino, a wide vista of
integration options is open to you.
Also, this tutorial will be useful for developers who are using the LotusScript
extension for MQSeries (MQLSX) today. MQLSX is not supported in the Lotus
Domino 6 environment, and since support for MQLSX will end on December 31,
2004, it is recommended that any new solutions be written in the Java language
within the Domino 6 environment.
After completing this tutorial, you should know how to integrate Lotus Domino and
WebSphere MQ using LotusScript and the Java language.
Required software
For the purposes of this tutorial, we'll be using Lotus Domino 6 and WebSphere MQ
5.3, which, at the time of writing, are the most current releases of those products.
For more information on the system requirements for running these applications, see
the documentation that accompanies them.
This tutorial guides you through the use of a Lotus Domino database that uses the
WebSphere MQ Java set of classes to put and get messages. You'll need a Lotus
Domino version 6 server, Domino Designer version 6, and a Lotus Notes version 6
client. The Domino database will put a message and get the message from a
WebSphere MQ queue. You'll also need a WebSphere MQ version 5.3 server
installed. If the WebSphere MQ server is not installed on the same machine as the
Lotus Domino server, you need to install the WebSphere MQ client on the same
machine as the Lotus Domino server.
You can download trial versions of the required Lotus software at no charge. All of
this software is accompanied by installation instructions.
Renaming MQSeries
MQSeries is taking on a new name -- WebSphere MQ. WebSphere is IBM's brand
for e-business which includes many individual products and offerings. Rebranding
the MQSeries name with the WebSphere software platform signals a
better-integrated e-business software platform. The MQSeries family of products will
continue to grow and develop in the way that has already made it the industry
standard for integration.
potential partner applications are on, what platform they're on, what language they're
written in, or what communication protocol they need to use in order to
communicate.
Applications designed and written using this interface are known as message
queuing applications, as they use the messaging and queuing. What exactly does
this mean?
There is another interface, called the Application Messaging Interface (AMI), that
you can use with WebSphere MQ. AMI provides a simple interface that application
programmers can use without needing to understand all the functions available in
MQI. The functions that are required in a particular installation are defined by a
system administrator, using services and policies. We will not discuss AMI in this
tutorial, just MQI.
This tutorial focuses on the WebSphere MQ classes for the Java language. The
WebSphere MQ classes for JMS use a JNDI namespace for their administered
objects, which is the expected operation of JMS client applications. Setting up a
JNDI-based repository is relatively complex, and hence is beyond the scope of this
tutorial.
WebSphere MQ messages
Messages are data sent from one program to another. A message consists of two
parts, the message descriptor and the application data, as illustrated below.
When a message is exchanged, the receiving program needs to know the layout of
the data. For example, suppose the message describes a person. The first 12 bytes
of the message could be the first name, the next 24 bytes could be the last name,
the next 30 bytes could be the first address line, the next 30 bytes could be the
second address line, and we could continue on from there. The receiving program
would know all this in advance and parse the message to extract the various parts of
the person message.
On the other hand, the message could be an order number, and the sending
program might like to know more about the order. The sending program would send
the message and get a reply message back with all the information about that order.
There are several questions you need to answer at the design stage that will affect
the way you create messages.
Types of messages
You can create several different types of messages. These are four of the most
common:
• Datagram: You should use a datagram when you do not require a reply
from the application that receives the message.
• Request: You should use a request message when you want a reply from
the application that receives the message.
• Reply: You should use a reply message when you reply to another
message.
• Report: Report messages inform applications about events such as the
occurrence of an error when processing a message. They can be
generated at any time, and they may arrive on a queue when your
application is not expecting them. Report messages can be generated by:
• A queue manager
• A message channel agent (if the agent cannot deliver the message,
for instance)
• An application (if the application cannot use the data in the message,
for instance)
For more information about messages, refer to the WebSphere MQ Application
Programming Guide, which is available on the WebSphere MQ CD-ROM. The
documentation is also available online in HTML and PDF formats after installing
WebSphere MQ.
The application data in the message can be in any format. As described in our
previous example, the data could represent a person, i.e., first name, last name,
address, etc. The data could be one long string, or it could include integers,
decimals, floats, and so on. The most important thing is that both programs -- the put
program and the get program -- need to know the layout of the data in the message.
There are several methods to ensure this. The simplest is documenting and
standardizing on message layouts for your system ahead of time. That way, when
applications are developed, they adhere to the standard message layout.
In our Java language example later in this tutorial, we'll use a string for the
application data in the message. To build a new message that may contain a string,
an integer, or a decimal, you create a new instance of the MQMessage class, and
use the writeXXX() methods to put data into the message buffer.
The following Java code creates a message and puts it onto a queue. You first
create the message, then put any type of data into the message buffer in the order
you want. For example, you write the age first with the writeInt() method, then you
write the string name with the writeUTF() method. This is just one example; there are
several other writeXXX() methods that you could use.
The following example will get the message from the queue.
For more information about writing application data in a message, refer to the
WebSphere MQ queues
A WebSphere MQ queue is a named object on which applications can put
messages, and from which applications can get messages. Messages are stored on
a queue, so if the putting application expects a reply to its message, it is free to do
other work while waiting for that reply. Applications access a queue by using the
Message Queue Interface (MQI).
Before a message can be put on a queue, the queue must have already been
created. A queue is owned by a queue manager, and that queue manager can own
many queues. However, each queue must have a name that is unique among
queues managed by a single queue manager.
Before using a queue, you must open it in your application program, specifying what
you want to do with it. For example, you can open a queue:
Types of queues
WebSphere MQ supports several types of queues:
1. Lotus Domino and the WebSphere MQ client are on the same box, and
the WebSphere MQ server is on another box.
2. Lotus Domino server and the WebSphere MQ server are on the same
box. With this setup, the WebSphere MQ client code is already installed
with the WebSphere MQ server.
The following two illustrations highlight these installations. For our purposes, it
doesn't matter which way you install the servers; this tutorial and the sample code
will work either way.
runmqsc [QMNAME]
4. If a listener has not already been started, start a listener program with the
following commands:
java MQIVP
The next panel provides the information you'll need when you run the MQIVP
program, and the results you should expect from it.
Verification results
The installation verification program requires some input. The prompts are:
Now that you have WebSphere MQ installed, you're ready to write Domino code that
takes advantages of its features.
Support issues
The majority of organizations integrating Lotus Domino and WebSphere MQ today
are using the MQSeries Link for LotusScript. This product supports Domino R4 and
R5, and MQSeries 5.2 and WebSphere MQ 5.3. (Note that in the transition from
version 5.2 to 5.3 of this software, IBM integrated MQSeries into its WebSphere
offerings, which is the reason for the name change.) The MQSeries Link for
LotusScript (MQLSX) will not be supported in the Domino 6 environment, and its
end-of-service date is December 31, 2004. Furthermore, you will no longer be able
to download MQLSX after January 2, 2004.
The question now is: How do we move from MQLSX to the Java platform? Hopefully
this tutorial will provide some guidance.
If you have Lotus Domino 5 or 6, you can still use earlier versions of WebSphere MQ
(5.1 or 5.2), but these versions do not include the necessary MQ Java classes. You
need to install the SupportPac MA88: MQSeries classes for Java and MQSeries
classes for Java Message Service. For more information about SupportPacs, visit
WebSphere MQ SupportPacs.
Using LS2J with Lotus Domino 6 allows developers to take advantage of all the
LotusScript front-end and back-end classes, instead of a writing a solution entirely in
the Java language, which provides access only to the back-end classes.
We'll provide three examples in this tutorial: one for the Lotus Notes client, one for
the browser client, and the last is a scheduled agent to get a message off of a
queue. The first example uses LS2J and the second uses a Lotus Domino agent
written entirely in the Java language. These first two examples put a message on a
queue and get a message from a queue. The third example is a scheduled agent
that will only get a message off of a queue. This last example is written entirely in
Java code, too.
Java library
The first example is for the Lotus Notes client. In this panel, we'll highlight the design
of the sample database that we'll be accessing with the client. (You can download
the complete database from Resources.)
The first part of the database we will discuss is the Java code used to put a
message on a queue and to get a message from a queue. With Lotus Domino
Designer 6, you have the capability to create Java libraries, just like you've been
able to create LotusScript libraries in the past.
You should be able to use the sample database with no modifications, but there are
some setup steps you'll need to walk through for Lotus Notes and Domino to work
properly. First, you'll need to edit the Java user classes parameter in the Notes.ini
file. You need to add the following line to the Notes.ini file:
JavaUserClasses=C:\WebSphereMQ\Java\lib;C:\WebSphereMQ\Java\lib\com.ibm.mq.jar;
C:\WebSphereMQ\tools\java\base\;C:\WebSphereMQ\Java\lib\connector.jar;
C:\WebSphereMQ\Java\lib\jta.jar;C:\WebSphereMQ\Java\lib\providerutil.jar;
C:\WebSphereMQ\Java\lib\com.ibm.mqjms.jar;C:\WebSphereMQ\Java\lib\ldap.jar;
C:\WebSphereMQ\Java\lib\jndi.jar;C:\WebSphereMQ\Java\lib\jms.jar;
C:\WebSphereMQ\Java\lib\fscontext.jar;
These Java user classes need to be added to the Lotus Notes client file and the
Lotus Domino server file. For this example, we've assumed that WebSphere MQ is
installed at C:\WebSphereMQ\; obviously, you'll need to change this to match your
environment.
Download the sample database and move it to your Domino 6 server. Open the
Domino Designer 6 client and the sample database. Expand Shared Code and
Script Libraries, then select DominoMQC. You'll notice two Java programs:
• MQGetC.java
• MQPutC.java
These are standalone Java applications; we'll look at them in more detail later in this
section. You can copy them from the Java library, save them as Java applications,
compile them, and then execute them. This is a good test to try out the Java code,
connectivity, and the put and the get of a message.
In this section, we'll use a Notes front end to access these applications. First,
however, we'll take a look a potential error that might cause you problems.
The problem is with the Java runtime environment. Lotus Domino 6 supports Java 2
Runtime Environment, Standard Edition 1.3.1 and java.exe is located in
c:\lotus\domino\jvm\bin. Make sure you are using this executable.
There is a workaround. Copy mqjbnd05.dll to the Lotus Domino binary directory (by
default, this directory is C:\Lotus\Domino).
Now let's look at the code behind this form. What follows is the LotusScript code that
will invoke the Java putMessage() method, which puts a message on a queue. In the
Options section, it's important to include the Use statement; this is where the Java
code is located. The Uselsx statement is required to use LS2J; it's the LotusScript
extension that allows LotusScript to execute Java methods. The Declarations
section initializes the objects. The Click routine sets the objects and gets the values
from the form and invokes the Java putMessage() method.
(Options)
Use "DominoMQC"
Uselsx "*javacon"
(Declarations)
'New LotusScript classes that access Java
Dim mySession As JavaSession
Dim myClass As JavaClass
Dim myObject As JavaObject
Dim port As Integer
Dim ws As NotesUIWorkSpace
MQPutC.java
The following is the Java code used to put a message on a queue. This is the code
that our put form from the previous panel is accessing. For more information about
the Java code, refer to the Java agent code explained section.
import com.ibm.mq.*;
public class MQPutC {
public MQPutC() {
}
public static void main(String args[]){
try {
String hostName = "gfbrich";
int port = 1414;
String channel = "JAVA.CHANNEL";
String mqManager = "QM_gfbrich";
String mqQname = "SYSTEM.DEFAULT.LOCAL.QUEUE";
String message = "This is my first message";
String returnStatus = putMessage(hostName, port, channel,
mqManager, mqQname, message);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String putMessage(String hostName, int port, String channel,
String mqManager, String mqQname, String message) throws Exception {
The putMessage() method is the most important part of the program. As we saw,
this is the method we call from LotusScript in the Domino database. The input
parameters are:
Now let's look at the code behind the form. The following listing is the LotusScript
code to get a message from a queue. It invokes the Java getMessage() method.
Again, remember that it's important to include the Use statement, and that the
Uselsx statement is required to use LS2J. The Click routine here sets the objects
and gets the values from the form and invokes the Java getMessage() method.
(Options)
Use "DominoMQC"
Uselsx "*javacon"
(Declarations)
'New LotusScript classes that access Java
Dim mySession As JavaSession
Dim myClass As JavaClass
Dim myObject As JavaObject
Dim port As Integer
Dim ws As NotesUIWorkSpace
Dim uidoc As NotesUIDocument
Sub Click(Source As Button)
MQGetC.java
The following is the Java code used to get a message off of a queue. This is the
code that our get form from the previous panel is accessing. For more information
about the Java code, refer to the Java agent code explained section.
import com.ibm.mq.*;
public class MQGetC {
public MQGetC() {
}
public static void main(String args[]){
try {
String hostName = "gfbrich";
int port = 1414;
String channel = "JAVA.CHANNEL";
String qManager = "QM_gfbrich";
String mqQname = "SYSTEM.DEFAULT.LOCAL.QUEUE";
String retrievedMessage = getMessage(hostName, port, channel,
qManager, mqQname);
System.out.println("Message = " + retrievedMessage);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String getMessage(String hostName, int port, String channel,
String mqManager, String mqQname) throws Exception {
String msgText = new String();
try {
MQEnvironment.hostname = hostName;
MQEnvironment.port = port;
MQEnvironment.channel = channel;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQQueueManager qMgr = new MQQueueManager(mqManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQGMO_FAIL_IF_QUIESCING;
MQQueue qName = qMgr.accessQueue(mqQname, openOptions, null, null, null);
The getMessage() method is the most important part of the program. As we saw in
the previous panel, this is the method we call from LotusScript in the Domino
database. The input parameters are:
Java agents
Our second example uses a Web browser for the client. There are two forms, one
for the put message and the other for the get message. For each form, there is a
corresponding Domino Java agent.
For the Java agents to call WebSphere MQ, you need to update the Java user
classes parameter in the Notes.ini file for the Domino server. Shut down the Domino
server, add the following line, then restart the server.
JavaUserClasses=C:\WebSphereMQ\Java\lib;C:\WebSphereMQ\Java\lib\com.ibm.mq.jar;
C:\WebSphereMQ\tools\java\base\;C:\WebSphereMQ\Java\lib\connector.jar;
C:\WebSphereMQ\Java\lib\jta.jar;C:\WebSphereMQ\Java\lib\providerutil.jar;
C:\WebSphereMQ\Java\lib\com.ibm.mqjms.jar;C:\WebSphereMQ\Java\lib\ldap.jar;
C:\WebSphereMQ\Java\lib\jndi.jar;C:\WebSphereMQ\Java\lib\jms.jar;
C:\WebSphereMQ\Java\lib\fscontext.jar;
The form also has a hidden field, SaveOptions, for which the default value is 0. This
indicates not to save the document into the Domino database after the Submit
button is pressed. If you want to save the document, remove the field or change the
default value to 1.
MQPutAgent
Now let's examine the Domino Java agent that will retrieve the field values from the
form and then put the message on the queue.
The agent gets a handle to the document doc and issues a getItemValueString() to
get the host name, channel, queue manager, queue, and message. It issues a
getItemValueInteger() for the port, since the port is an integer value.
The agent sets environment values for the host name, channel, and port. The agent
creates a new queue manager, new message, and new message options objects. It
accesses the queue name and, finally, puts the message on the queue. For more
information about the Java code, refer to the Java agent code explained section.
import
com.ibm.mq.*;
import
java.io.PrintWriter;
import
lotus.domino.*;
public
class
JavaAgent
extends
AgentBase {
public
void
NotesMain()
{
try {
Session
session =
getSession();
AgentContext
agentContext
=
session.getAgentContext();
PrintWriter
pw =
getAgentOutput();
pw.println("Content-Type:
text/html");
pw.println("<html><head><title>DominoMQ</title></head><body>");
pw.println("<table><tr>");
pw.println("<td
width=\"200\"
rowspan=\"2\"><img
src=\"
/DominoMQ.nsf/ibmlogo-S.gif?OpenImageResource\"></td>");
pw.println("<td><img
src=\"
/DominoMQ.nsf/LOT_18P.GIF?OpenImageResource\"></td>");
pw.println("</tr><tr><td>");
pw.println("<img
src=\"
/DominoMQ.nsf/WS_18P.GIF?OpenImageResource\"></td>");
pw.println("</tr></table>");
pw.println("<body><h1>DominoMQ
Put</h1>");
Document
doc =
agentContext.getDocumentContext();
String
returnStatus
= null;
pw.println("<p>Host:
" +
doc.getItemValueString("hostName"));
pw.println("<p>Channel:
" +
doc.getItemValueString("channel"));
pw.println("<p>Port:
" +
doc.getItemValueInteger("port"));
pw.println("<p>Message:
" +
doc.getItemValueString("message"));
MQEnvironment.hostname
=
doc.getItemValueString("hostName");
MQEnvironment.channel
=
doc.getItemValueString("channel");
MQEnvironment.port
=
doc.getItemValueInteger("port");
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
MQQueueManager
qMgr = new
MQQueueManager(doc.getItemValueString("mqManager"));
int
openOptions
=
MQC.MQOO_INPUT_AS_Q_DEF
|
MQC.MQOO_OUTPUT;
MQQueue mqQ
=
qMgr.accessQueue(doc.getItemValueString("mqQname"),openOptions);
MQMessage
mqMsg = new
MQMessage();
mqMsg.writeUTF(doc.getItemValueString("message"));
MQPutMessageOptions
pmo = new
MQPutMessageOptions();
mqQ.put(mqMsg,pmo);
mqQ.close();
qMgr.disconnect();
pw.println("<h2>Message
successfully
put</h2>");
pw.println("</body></html>");
}
catch(NotesException
ne) {
System.out.println("A
Lotus
Domino
error
occurred: "
+ ne.id + "
" +
ne.text);
}
catch
(MQException
ex) {
System.out.println("A
WebSphere
MQ error
occurred :
Completion
code " +
ex.completionCode
+ " Reason
code " +
ex.reasonCode);
}
catch
(java.io.IOException
ex) {
System.out.println("An
error
occurred
writing to
the message
buffer: " +
ex);
}
catch(Exception
e) {
e.printStackTrace();
}
}
}
The form also has a hidden field, SaveOptions, with a default value of 0. This
indicates not to save the document into the Domino database after the Submit
button is pressed. If you want to save the document, remove the field or change the
default value to 1.
MQGetAgent
Now let's discuss the Domino Java agent that will retrieve the field values from the
form and then get the message from the queue.
The agent gets a handle to the document doc and issues a getItemValueString() to
get the host name, channel, queue manager, queue, and message. It issues a
getItemValueInteger() for the port, since the port is an integer value.
The agent sets environment values for the host name, channel, and port. The agent
creates a new queue manager, new message, and new message options objects. It
accesses the queue name and finally gets the message from the queue. If there is
still no message on the queue at that point, the get operation will wait for
approximately 10 seconds for a message. If there is no message, a Completion
Code of 2 and a Reason Code of 2033 will be printed to the Domino console. For
more information about the Java code, refer to the Java agent code explained
section.
import
com.ibm.mq.*;
import
java.io.PrintWriter;
import
lotus.domino.*;
public
class
JavaAgent
extends
AgentBase {
public
void
NotesMain()
{
try {
Session
session =
getSession();
AgentContext
agentContext
=
session.getAgentContext();
PrintWriter
pw =
getAgentOutput();
pw.println("Content-Type:
text/html");
pw.println("<html><head><title>DominoMQ</title></head><body>");
pw.println("<table><tr>");
pw.println("<td
width=\"200\"
rowspan=\"2\"><img
src=\"
/DominoMQ.nsf/ibmlogo-S.gif?OpenImageResource\"></td>");
pw.println("<td><img
src=\"
/DominoMQ.nsf/LOT_18P.GIF?OpenImageResource\"></td>");
pw.println("</tr><tr><td>");
pw.println("<img
src=\"
/DominoMQ.nsf/WS_18P.GIF?OpenImageResource\"></td>");
pw.println("</tr></table>");
pw.println("<body><h1>DominoMQ
Get</h1>");
String
msgText =
new
String();
Document
doc =
agentContext.getDocumentContext();
pw.println("<p>Host:
" +
doc.getItemValueString("hostName"));
pw.println("<p>Channel:
" +
doc.getItemValueString("channel"));
pw.println("<p>Port:
" +
doc.getItemValueInteger("port"));
MQEnvironment.hostname
=
doc.getItemValueString("hostName");
MQEnvironment.channel
=
doc.getItemValueString("channel");
MQEnvironment.port
=
doc.getItemValueInteger("port");
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
MQQueueManager
qMgr = new
MQQueueManager(doc.getItemValueString("mqManager"));
int
openOptions
=
MQC.MQOO_INPUT_AS_Q_DEF
|
MQC.MQOO_OUTPUT;
MQQueue mqQ
=
qMgr.accessQueue(doc.getItemValueString("mqQname"),
openOptions);
MQMessage
retrievedMessage
= new
MQMessage();
MQGetMessageOptions
gmo = new
MQGetMessageOptions();
gmo.options
=
MQC.MQGMO_WAIT
|
MQC.MQGMO_FAIL_IF_QUIESCING
|
MQC.MQGMO_NO_SYNCPOINT;
gmo.waitInterval
= 10000;
mqQ.get(retrievedMessage,gmo);
msgText =
retrievedMessage.readUTF();
mqQ.close();
qMgr.disconnect();
pw.println("<h2>Message:
" + msgText
+ "</h2>");
pw.println("</body></html>");
}
catch(NotesException
ne) {
System.out.println("A
Lotus
Domino
error
occurred: "
+ ne.id + "
" +
ne.text);
}
catch
(MQException
ex) {
System.out.println("A
WebSphere
MQ error
occurred :
Completion
code " +
ex.completionCode
+ " Reason
code " +
ex.reasonCode);
}
catch
(java.io.IOException
ex) {
System.out.println("An
error
occurred
writing to
the message
buffer: " +
ex);
}
catch(Exception
e) {
e.printStackTrace();
}
}
}
import
com.ibm.mq.*;
import
lotus.domino.*;
public
class
JavaAgent
extends
AgentBase {
public
void
NotesMain()
{
String
hostname =
"gfbrich";
String
channel =
"JAVA.CHANNEL";
Integer
port = new
Integer(1414);
String
mqManager =
"QM_gfbrich";
String
mqQname =
"SYSTEM.DEFAULT.LOCAL.QUEUE";
String
msgText =
new
String();
boolean
forever =
true;
try {
Session
session =
getSession();
AgentContext
agentContext
=
session.getAgentContext();
Database db
=
agentContext.getCurrentDatabase();
MQEnvironment.hostname
= hostname;
MQEnvironment.channel
= channel;
MQEnvironment.port
=
port.intValue();
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
MQQueueManager
qMgr = new
MQQueueManager(mqManager);
int
openOptions
=
MQC.MQOO_INPUT_AS_Q_DEF
|
MQC.MQOO_OUTPUT;
MQQueue mqQ
=
qMgr.accessQueue(mqQname,
openOptions);
MQMessage
retrievedMessage
= new
MQMessage();
MQGetMessageOptions
gmo = new
MQGetMessageOptions();
gmo.options
=
MQC.MQGMO_WAIT
|
MQC.MQGMO_FAIL_IF_QUIESCING
|
MQC.MQGMO_NO_SYNCPOINT;
gmo.waitInterval
= 10000;
while
(forever) {
mqQ.get(retrievedMessage,gmo);
msgText =
retrievedMessage.readUTF();
retrievedMessage.messageId
= null;
retrievedMessage.correlationId
= null;
Document
doc =
db.createDocument();
doc.replaceItemValue("Form",
"MQScheduledGetForm");
doc.replaceItemValue("hostName",
hostname);
doc.replaceItemValue("port",
port);
doc.replaceItemValue("channel",
channel);
doc.replaceItemValue("mqManager",
mqManager);
doc.replaceItemValue("mqQname",
mqQname);
doc.replaceItemValue("message",
msgText);
if
(doc.save())
System.out.println("Document
created and
saved");
else
System.out.println("Something
went
wrong");
doc.recycle();
}
mqQ.close();
qMgr.disconnect();
}
catch(NotesException
ne) {
System.out.println("A
Lotus
Domino
error
occurred: "
+ ne.id + "
" +
ne.text);
}
catch
(MQException
ex) {
if
(ex.reasonCode
== 2033) {
//Queue is
empty
}
else
{
System.out.println("A
WebSphere
MQ error
occurred :
Completion
code " +
ex.completionCode
+ " Reason
code " +
ex.reasonCode);
}
}
catch
(java.io.IOException
ex) {
System.out.println("An
error
occurred
writing to
the message
buffer: " +
ex);
}
catch(Exception
e) {
e.printStackTrace();
}
}
}
In the first part of the program, we initialize some variables. We use the class Integer
for the port because this is what Domino requires for a numeric field. Later in the
program, we use the intValue() method on the port object, which returns the primitive
int value for use by the port environment value. The last value, forever, is used for a
while loop to retrieve all messages on the queue. The code will loop forever until
there are no more messages on the queue, which will throw an exception and exit
the loop.
String
hostname =
"gfbrich";
String
channel =
"JAVA.CHANNEL";
Integer
port = new
Integer(1414);
String
mqManager =
"QM_gfbrich";
String
mqQname =
"SYSTEM.DEFAULT.LOCAL.QUEUE";
String
msgText =
new
String();
boolean
forever =
true;
The next three lines initialize the objects used for Domino. We start with a Session,
and then AgentContext, which represents the agent environment of our program.
Lastly, we get a handle to the current Domino database.
Session
session =
getSession();
AgentContext
agentContext
=
session.getAgentContext();
Database db
=
agentContext.getCurrentDatabase();
MQEnvironment.hostname
= hostname;
MQEnvironment.channel
= channel;
MQEnvironment.port
=
port.intValue();
We are now ready to connect to the queue manager. We create a new instance of
the MQQueueManager class.
MQQueueManager
qMgr = new
MQQueueManager(mqManager);
Next, we access the queue and create new message and message options objects.
One of the options you should note here is MQGMO_WAIT. This option, along with
the wait interval value, will have the program wait on a queue if there are no
messages for the desired time in milliseconds. In our example, we'll wait 10 seconds
for a message if the queue is empty.
int
openOptions
=
MQC.MQOO_INPUT_AS_Q_DEF
|
MQC.MQOO_OUTPUT;
MQQueue mqQ
=
qMgr.accessQueue(mqQname,
openOptions);
MQMessage
retrievedMessage
= new
MQMessage();
MQGetMessageOptions
gmo = new
MQGetMessageOptions();
gmo.options
=
MQC.MQGMO_WAIT
|
MQC.MQGMO_FAIL_IF_QUIESCING
|
MQC.MQGMO_NO_SYNCPOINT;
gmo.waitInterval
= 10000;
The while loop will get all messages on the queue, one at a time. It's important to set
the message and correlation IDs to null after each message is retrieved. The
program will create a new document in the Domino database. The document will
contain the host name, port, channel, queue manager, queue name, and the
retrieved message.
while
(forever) {
mqQ.get(retrievedMessage,gmo);
msgText =
retrievedMessage.readUTF();
retrievedMessage.messageId
= null;
retrievedMessage.correlationId
= null;
Document
doc =
db.createDocument();
doc.replaceItemValue("Form",
"MQScheduledGetForm");
doc.replaceItemValue("hostName",
hostname);
doc.replaceItemValue("port",
port);
doc.replaceItemValue("channel",
channel);
doc.replaceItemValue("mqManager",
mqManager);
doc.replaceItemValue("mqQname",
mqQname);
doc.replaceItemValue("message",
msgText);
if
(doc.save())
System.out.println("Document
created and
saved");
else
System.out.println("Something
went
wrong");
doc.recycle();
}
The last piece of code closes the queue, and disconnects from the queue manager.
mqQ.close();
qMgr.disconnect();
Section 8. Wrap up
Summary
Lotus Domino enables individuals to access information, expertise, and resources
regardless of time or geography. WebSphere MQ enables programs to communicate
with one another across a network of unlike components -- processors, operating
systems, subsystems, and communication protocols -- using a consistent application
programming interface.
Lotus Domino usually is not the only system in an enterprise. There are other
systems on other platforms. These systems could be written in Visual Basic, C,
COBOL, or the Java language, and you need to share data between Lotus Domino
and these systems. WebSphere MQ is the middleware that will enable Lotus Domino
to communicate with virtually any program on any platform you have in your
enterprise.
Hopefully, this tutorial will help you integrate your Domino databases with
WebSphere MQ. Also, if you are currently using the MQSeries Link for LotusScript
(MQLSX), then this tutorial should help you move to a Java platform-based -- and
supported -- solution.
Resources
Learn
• Here are a few IBM redbooks on Domino, Domino Designer, and WebSphere
MQ.
• Domino Designer 6: A Developer's Handbook
• What's new with IBM Lotus Domino 6 for iSeries
• Upgrading to Lotus Notes and Domino 6
• Lotus Domino 6 for Linux
• IBM Lotus Domino 6 for iSeries implementation
• MQSeries primer
• MQSeries publish/subscribe applications
Broadcast, as well as for customers and internal field enablement. He works with
Lotus product management to bring the latest and greatest technologies on Lotus
application development and enterprise integration to you. During his spare time, he
developed and supported a Lotus Notes utility called CalPrint. George resides in the
Chicago area. He can be reached at george_brichacek@us.ibm.com