The Node.js samples are based on https://github.com/ibm-messaging/mq-mqi-nodejs/tree/master/samples and have been tested with Node.js v22.14.0
Install/unzip IBM MQ client
IBM MQ MacOS toolkit for developers download
Add
/opt/mqm/bin
and
/opt/mqm/samp/bin
, to the PATH by editing /etc/paths
export DYLD_LIBRARY_PATH=/opt/mqm/lib64
export MQ_INSTALLATION_PATH=/opt/mqm
Windows client v 9.1.1.0 download
Linux Ubuntu client v 9.1.1.0 download
To run the examples cd to the Node.js directory and install the prerequsites by running :
npm install
basicput.js - Puts message to a queue
basicget.js - Gets message from a queue
basicsubscribe.js - Subscribes to a topic string and gets publications/messages
basicpublish.js - Publishes messages to a topic string
basicrequest.js - Puts a message on a request queue and waits for a response
basicresponse.js - Gets message from a request queue, does something with the message and puts it to the reply queue.
sampleput.js - Puts message to a queue
sampleget.js - Gets message from a queue
samplesubscribe.js - Subscribes to a topic string and gets publications/messages
samplepublish.js - Publishes messages to a topic string
samplerequest.js - Puts a message on a request queue and waits for a response
sampleresponse.js- Gets message from a request queue, does something with the message and puts it to the reply queue.
boilerplate.js - Common class, manages the connection to queue manager, contains generic consumer and producer code.
To enable token-based authentication, ensure you have a configured token issuer and queue manager JWT README and then edit the JWT_ISSUER
block in the env.json file
"JWT_ISSUER" : [{
"JWT_TOKEN_ENDPOINT":"https://<KEYCLOAK_URL>/realms/master/protocol/openid-connect/token",
"JWT_TOKEN_USERNAME":"app",
"JWT_TOKEN_PWD":"passw0rd",
"JWT_TOKEN_CLIENTID":"admin-cli",
"JWT_KEY_REPOSITORY": "path/to/tokenIssuerKeystore"
}]
For JWT authentication via JWKS, make sure JWT_KEY_REPOSITORY
points to your token issuer's public certificate and your queue manager is configured to retrieve the JWKS
If you would like to proceed with JWT authentication without JWKS validation, edit the endpoint to use the correct URL (beginning with http) and leave JWT_KEY_REPOSITORY
blank
The put application places a json object onto the queue. To run the basic application with logging, run
On Mac and Linux:
DEBUG=amqs*:* node basicput.js
On Windows:
SET DEBUG=amqs*:*
node basicput.js
The get application reads a json object from the queue.
To run the basic application with logging, run
On Mac and Linux:
DEBUG=amqs*:* node basicget.js
On Windows:
SET DEBUG=amqs*:*
node basicget.js
The sample get and put applications have the common MQ boiler plate factorised into a library and make use of promises.
To run with logging, run
On Mac and Linux:
DEBUG=sample*:*,boiler:* node sampleput.js
and
DEBUG=sample*:*,boiler:* node sampleget.js
On Windows:
SET DEBUG=sample*:*,boiler:*
node sampleput.js
and
SET DEBUG=sample*:*,boiler:*
node sampleget.js
To set the application name, which is useful for problem determination, SET
the envrionment variable ApplName
. eg.
On Mac and Linux:
DEBUG=sample*:*,boiler:* ApplName="sample put app" node sampleput.js
and
DEBUG=sample*:*,boiler:* ApplName="sample get app" node sampleget.js
The publish application publishes a json object onto a topic. To run the basic applications with logging, run
On Mac and Linux:
DEBUG=amqs*:* node basicpublish.js
On Windows:
SET DEBUG=amqs*:*
node basicpublish.js
The subscribe application subscribes to a topic.
To run with logging, run
On Mac and Linux:
DEBUG=amqs*:* node basicsubscribe.js
On Windows:
SET DEBUG=amqs*:*
node basicsubcscribe.js
The sample publish and subscribe applications have the common MQ boiler plate factorised into a library and makes use of promises.
To run with logging, run
On Mac and Linux
DEBUG=sample*:*,boiler:* node samplepublish.js
and
DEBUG=sample*:*,boiler:* node samplesubscribe.js
It is possible to set the application name, by setting the environment value ApplName
.
To create a durable subscription set the envrionment variable DURABLE
to any value. eg.
DEBUG=sample*:*,boiler:* DURABLE=1 ApplName="sample durable subscriber" node samplesubscribe.js
On Windows:
SET DEBUG=sample*:*,boiler:*
node samplepublish.js
and
SET DEBUG=sample*:*,boiler:*
node samplesubscribe.js
The request application create a dynamic queue for a reply, and places a json object consisting of the request onto a queue, then waits for a response to the request.
To run the basic applications with logging, run
On Mac and Linux:
DEBUG=amqs*:* node basicrequest.js
and
DEBUG=amqs*:* node basicresponse.js
On Windows:
SET DEBUG=amqs*:*
node basicrequest.js
and
SET DEBUG=amqs*:*
node basicresponse.js
The request / response applications have the common MQ boiler plate factorised into a library and makes use of promises.
To run the sample applications with logging, run
On Mac and Linux:
DEBUG=sample*:*,boiler:* node sampleresponse.js
and
DEBUG=sample*:*,boiler:* node samplerequest.js
On Windows:
SET DEBUG=sample*:*,boiler:*
node sampleresponse.js
and
SET DEBUG=sample*:*,boiler:*
node samplerequest.js
It is possible to set the application name, by setting the environment value ApplName
.