We have just added some simple C samples in the IBM MQ mq-dev-patterns repo to make it easier for C developers to get started with writing applications for IBM MQ. The samples are structured to be functionally compatible with other language examples in the repo, and even consume the same env.json file, to make it easier to use them interchangeably.
The following samples are available:
- 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
Instructions on how to get up and running are documented in the README.md. I tested them on my Mac as follows:
Initial setup using the IBM MQ Toolkit for MacOS:
- brew tap ibm-messaging/ibmmq
- brew install ibm-messaging/ibmmq/mqdevtoolkit
- export PATH=/opt/mqm/bin:$PATH
- export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/mqm/lib64
Clone the mq-dev-patterns repo
- git clone https://github.com/ibm-messaging/mq-dev-patterns.git
- cd mq-dev-patterns
Configure your env.json file to match your queue manager config. Run the samples:
- cd C
- make
- DEBUG=true ./sampleput
- DEBUG=true ./sampleget
Thanks to @Mark Taylor for putting the samples together. Feedback welcome, please raise an issue in the mq-dev-patterns repo.