This is part of a series of small blog posts which will cover some of the smaller, perhaps less likely to be noticed, features of IBM MQ. Read other posts in this series.
The IBM MQ product supplies a good number of sample applications, built and ready to run. Many aspects of the MQ API are covered, not just putting and getting. There are samples for message properties, inquiring queue attributes, triggered samples and many more.
If you have a primary installation of IBM MQ, then the sample directory (see below) is added to your path.
- %MQ_INSTALLATION_PATH%\Tools\c\Samples\Bin64
on Windows
- $MQ_INSTALLATION_PATH/samp/bin
on Unix
However, if you have more than one installation you will find yourself needing to add the samples to your path because using the setmqenv control command to switch over the installation you are using, does not add the samples to your path.
I use the samples a lot in my online IBM MQ training courses to ensure that you are able to learn about whichever MQ subject is at hand without having to download and install lots of other applications, so I prefer to have them in my path at all times, however, I also have a number of installations (to ensure the training courses work whichever level of IBM MQ you are using to do them) so I am regularly switching between them.
I decided to make a small script for switching installations instead of only using the setmqenv control command. This script would run the setmqenv control command, plus add the samples to the path, and maybe display something to show what environment you are now using. I was imagining that I would have to figure out how to remove the old samples directory from my path before I could add the new one, until I came across this delightful snippet of information in Knowledge Center.
The setmqenv command removes all directories for all IBM MQ installations from the environment variables before adding new references to the installation for which you are setting up the environment for.
For those that are interested, my Windows script is provided at the end of this post.
Even if you only have a single primary installation of IBM MQ, the setmqenv control command is still useful because it also sets a number of environment variables as shown in the following table.
Environment Variable |
Contains |
MQ_DATA_PATH |
The location of the IBM MQ data directory. |
MQ_ENV_MODE |
32 or 64 bit. |
MQ_FILE_PATH |
Windows only - same as MQ_INSTALLATION_PATH |
MQ_INSTALLATION_NAME |
The installation name associated with a particular installation of IBM MQ. |
MQ_INSTALLATION_PATH |
The high-level directory in which IBM MQ is installed. |
MQ_JAVA_DATA_PATH |
Specifies the directory for log and trace output. |
MQ_JAVA_INSTALL_PATH |
The directory where IBM MQ classes for JMS is installed. |
MQ_JAVA_LIB_PATH |
The directory where the IBM MQ classes for JMS libraries are stored. |
MQ_JRE_PATH |
The location of the JRE shipped with IBM MQ. |
Having these environment variables set does make it much easier to write scripts that will work regardless of where MQ directories are located on your machine.
In the process of writing this post, I also discovered a flag on setmqenv that I had forgotten about. If you want to remove all references to MQ directories from environment variables such as your path, and also remove the various MQ* environment variables that are set (see above), then you can use this command.
setmqenv -r
I couldn't decide, when planning to write this post, whether it should be a Little Gem, or an MQuirk. On the one hand it is a quirk of IBM MQ that the samples are not in the path unless you have a primary installation, but on the other hand it is a gem of a feature that the setmqenv control command cleans up your environment of all MQ directories before updating it with the new stuff.
cls
@set INST=%1
@set INST0=910GA
@REM ****************************************************************
@REM * Need at least one installation in order to run setmqenv or *
@REM * dspmqinst, assuming that there is no primary. If there was *
@REM * always a primary installation of MQ on the machine, this *
@REM * would not be necessary. *
@REM ****************************************************************
@if {%MQ_INSTALLATION_PATH%}=={} (
set BASEBIN=e:\mqm9100\bin
) else (
set BASEBIN=%MQ_INSTALLATION_PATH%\bin
)
@if {%INST%}=={} set INST=%INST0%
@if {%INST%}=={?} (
echo Enter one of the following:
%BASEBIN%\dspmqinst | grep InstName
goto EXIT
)
@call %BASEBIN%\setmqenv -n %INST%
@REM ****************************************************************
@REM * Helpfully, setmqenv removed EVERYTHING from the PATH that is *
@REM * related to IBM MQ, so you can safely add back in the samples *
@REM * to the path after running setmqenv. *
@REM ****************************************************************
set PATH=%PATH%;%MQ_INSTALLATION_PATH%\Tools\c\Samples\Bin64
dspmqver.exe -f 902
title MQ Environment : %MQ_INSTALLATION_NAME%
:EXIT
#Little-Gem#IBMMQ#ChampionsCorner