These samples use the C MQI to demonstrate basic messaging operations.
- Install the IBM MQ client for your system, or unpack the Redistributable Client package if available.
- The SDK component is needed in order to compile these programs.
- You also need a C compiler
sampleput.c - Puts message to a queue
sampleget.c - Gets message from a queue
samplesubscribe.c - Subscribes to a topic string and gets publications/messages
samplepublish.c - Publishes messages to a topic string
samplerequest.c - Puts a message on a request queue and waits for a response
sampleresponse.c- Gets message from a request queue, does something with the message and puts it to the reply queue.
common.c - Common functions, including managing the connection to the queue manager
config.c - A simple parser for the configuration file
The connection to the queue manager demonstrates a variety of approaches. Choices are made based on the configuration. These include
- Authentication
- Client or local connections
- TLS when using clients
- Application name used by Uniform Clusters
On Linux and MacOS, you can use the Makefile by simply running make. The generated programs are created in the current directory. If you have installed MQ into a non-default location, then you may need to change the directories named in the Makefile.
On Windows, the win_dev.bat
script sets the environment for the Visual Studio 2022 C compiler. And then the
win_bld.bat
script compiles the programs. Default installation paths are assumed, so you might need to edit these
scripts for your system.
All of the programs read a JSON-formatted configuration file. The name of the file can be given as a command-line parameter or by setting the JSON_CONFIG environment variable. If neither is set, the env.json file from the parent directory is used.
These samples do not use a real JSON parsing library, and are sensitive to the exact layout of the configuration file. In particular, each item is expected to be on a separate line of the file. The default format, from the file in the root of this repository, should be referred to.
All configuration parameters can also be set through environment variables. See config.h for the names of these environment variables.
Setting the DEBUG
environment variable to any value causes the active configuration to be printed.
Apart from the optional command line parameter naming the configuration file, there are no other parameters to any of the programs.
You might need to run setmqenv
to create environment variables pointing at your MQ installation
libraries. And on MacOS, the DYLD_LIBRARY_PATH
will usually need to be set to include the
/opt/mqm/lib64
directory.
See here for
more information about setmqenv
.
The sampleput
application places a short string message onto the queue.
The sampleget
application reads all messages from the queue and displays the contents.
Run these samples as a pair.
Start the samplesubcribe
program in one window (or in the background) and immediately afterwards start the
samplepublish
program in another window.
Run these samples as a pair.
Start the sampleresponse
program in one window (or in the background) and immediately afterwards start the
samplerequest
program in another window.