You may already know that you can use DB2 and MQ together. For example, through Q Replication
, by using DB2's MQ UDFs
, or by coordinating the commit of transactions
to DB2 and MQ. However, I find that a lot of DB2 people are hesitant to try these features because they're unfamiliar with MQ. That really shouldn't stop them :) Especially now. Starting with 9.7 FP4, DB2 has a new command (actually, much improved command) that makes it very easy to set up MQ for use with DB2. This command
is geared towards use with Q Replication, but the MQ objects it creates could be used with any function combining DB2 and MQ.
That got me thinking about the fastest way to get started with MQ. As I've said in the past, I think it's best to set up a simple scenario and go from there. That's what I'm going to show in this post. It should take about 15 minutes max. Of course, if you prefer to start with step-by-step introduction with an introduction to concepts, MQ has some excellent introductory tutorials
and a Flash overview.
I will not show an end-to-end configuration for any of the features I mentioned in the first paragraph. Instead, all I'm going to do is show you how to set up two MQ servers (queue managers) and the objects they need to be able to pass messages between them (queues, channels, and listeners). That will help keep the post short and simple. You can then watch a video here on ChannelDB2 that shows one way you can start using these MQ objects and verify they work. I also plan to post a few more how-to scenarios that include the use of this command.
Before You Start
In the next section, I have seven instructions and a script that show you what to do. I've written these to be used with a single system running Windows (e.g., a notebook), but you can work from a UNIX system with just a few changes to the instructions. However, you need two things before you start.
First, you'll need a copy of MQ V7. If you don't have one, you can download it from one of two places - IBM's Passport Advantage or the MQ pages on ibm.com. You should be able to download from Passport Advantage if you've purchased DB2 or InfoSphere Warehouse. That's because most DB2 and InfoSphere Warehouse editions include a copy of MQ. Otherwise, if you're just kicking the tires, you can download an evaluation copy of MQ from the WebSphere MQ pages on ibm.com.
Next, you'll need a copy of a DB2 product so that you have the new command. If you have a DB2 server and it's at a level earlier than 9.7 FP4, you can get the command by upgrading your DB2 to the latest fix pack. If you cannot upgrade your DB2 server at this time, the new command is also found in the IBM Data Server Client. You can download and install the latest release of the Client from ibm.com's DB2 pages
without affecting your DB2 server.
Do It Yourself
At a high level, the instructions and commands here create a configuration that looks like the following:
The instructions are as follows:
1. Bring up a DB2 command window, create a directory called myscripts under, say, C:, and switch to it:
2. Copy and paste the following text (explained later) into a file named mq.asnclp in c:\myscripts:
asnclp session set to q replication;
create mq script
config type u
mqserver 1 name sample mqhost "spongebob.svl.ibm.com" mqport "2404",
mqserver 2 name cognos mqhost "spongebob.svl.ibm.com" mqport "2405";
3. Change "spongebob.svl.ibm.com" to the host name or IP address of your system (or 'localhost' if you prefer) and save the file.
4. Issue the following command from your DB2 command window:
5. Run the following two batch files (explained later) that were generated by the asnclp command:
You may want to redirect stdout to a file so that you can look at the output later. If you want to try this exercise from UNIX, run the two shell scripts that were also generated by the asnclp command:
You should now have two running queue managers, one named SAMPLE and one named COGNOS, along with all the objects needed for them to send messages to each other.
6. You can verify your queue managers are running by issuing the following command:
The output from this command should read as follows:
7. You can verify the queues are correct using the DB2 Replication Center.
This requires you create a few tables for Q Replication, but you do not have to run Q Replication just to verify queues. See how to do it in the ChannelDB2 video titled Verifying MQ for Q Replication
. At some point, I'll have posts that show other ways to verify your MQ will work for DB2 needs.
What's in the File called mq.asnclp?
Like I said earlier, the asnclp Create MQ Script command
is geared towards use with Q Replication but the resulting MQ objects can be used any way you want. For this exercise, though, the important things to know are the following:
- The recommended name for your MQ server (queue manager) is the same as the database it will be used with.
- In this example, I assume you will eventually have databases called Sample and Cognos.
- This is not required, just a recommendation.
- The command needs the host name or IP address for the system where each queue manager will be created.
- That's the first quoted string in each of the last two lines ("spongebob.svl.ibm.com").
- For this exercise, the DB2 servers and MQ servers must be colocated on the same system(s).
- Each queue manager needs a TCP/IP port where it receives messages from the other queue manager.
- That's the second quoted string in each of the last two lines ("2404" and "2405").
What's in the Batch Files and Shell Scripts?
The asnclp command uses the information in mq.asnclp to create four files - two batch files for Windows and two shell scripts for UNIX. Each file can create one queue manager and all necessary MQ objects (queues, channels, listener) for that queue manager. The name of the queue manager is included in the file name.
These batch files/scripts first create an MQ script file that define 6-7 MQ objects. They then run three MQ commands - one to create the queue manager, one to start the queue manager, and one to pass the MQ script to the queue manager.
You'll eventually want to learn more about these objects and MQ's commands after you finish working with this post. For example, what's a channel or how do I stop and restart queue managers :) The MQ Information Center is an excellent resource for this. That's were the tutorial and Flash overview are. It also contains reference information about queue manager commands
and MQ scripting commands