This repo hosts sample code referred to and used as part of tutorials for IBM MQ on IBM Developer.
We have a wealth of messaging patterns, represented in many languages, including Java, .NET, Python, Node.js and Golang. They are available at the mq-dev-patterns repo, here!
Feel free to use code from the mq-dev-patterns repo to create your own messaging applications.
gettingStarted/jms
samples with TLS (IBM DDC MQ Badge Lab)For reference these instructions were built from this tutorial. Check it out for additional hints and tips.
cd mq-dev-samples/gettingStarted/jms
cd mq-dev-samples\gettingStarted\jms
javax.jms-api-2.0.1.jar
jarcurl -o javax.jms-api-2.0.1.jar https://repo1.maven.org/maven2/javax/jms/javax.jms-api/2.0.1/javax.jms-api-2.0.1.jar
com.ibm.mq.allclient-9.2.2.0.jar
jarcurl -o com.ibm.mq.allclient-9.2.2.0.jar https://repo1.maven.org/maven2/com/ibm/mq/com.ibm.mq.allclient/9.2.2.0/com.ibm.mq.allclient-9.2.2.0.jar
qmgrcert.pem
to the mq-dev-samples/gettingStarted/jms
directorycp <YOUR_DOWNLOAD_DIRECTORY>/qmgrcert.pem .
(Linux) or copy <YOUR_DOWNLOAD_DIRECTORY>\qmgrcert.pem .
(Windows)
keytool
to create a client .p12
trust storekeytool -keystore clientTruststore.p12 -storetype pkcs12 -importcert -file qmgrcert.pem -alias server-certificate
clientTruststore.p12
. It's important to remember this password as we'll use it when we run the sample later.yes
to trust this certificateNavigate to the "Application Credentials" tab of your cloud MQ service instance.
Click add
, then create a user called "app". Click Add and generate API key
, which will bring up your API token. Copy this and save it somewhere as you'll need it in the application you run to authenticate yourself to your MQ instance.
Open the com/ibm/mq/samples/jms/JmsPut.java
file (Linux) or com\ibm\mq\samples\jms\JmsPut.java
(Windows) in your favorite editor
Uncomment the following line
cf.setStringProperty(WMQConstants.WMQ_SSL_CIPHER_SUITE, "*TLS12");
Modify the following variables to match your IBM MQ configuration
private static final String HOST = "_YOUR_HOSTNAME_"; // Host name or IP address
private static final int PORT = 1414; // Listener port for your queue manager
private static final String CHANNEL = "DEV.APP.SVRCONN"; // Channel name
private static final String QMGR = "QM1"; // Queue manager name
private static final String APP_USER = "app"; // User name that application uses to connect to MQ
private static final String APP_PASSWORD = "_APP_PASSWORD_"; // Password that the application uses to connect to MQ
private static final String QUEUE_NAME = "DEV.QUEUE.1"; // Queue that the application uses to put and get messages to and from
mq-dev-samples/gettingStarted/jms
(Linux) or mq-dev-samples\gettingStarted\jms
(Windows)JmsPut.java
application
javac -cp ./com.ibm.mq.allclient-9.2.2.0.jar:./javax.jms-api-2.0.1.jar com/ibm/mq/samples/jms/JmsPut.java
javac -cp .\com.ibm.mq.allclient-9.2.2.0.jar;.\javax.jms-api-2.0.1.jar com\ibm\mq\samples\jms\JmsPut.java
JmsPut.class
file alongside your JmsPut.java
source filejmsPut
applicationExecute your Java code, specifying the clientTruststore.p12
and password
you set up earlier
java -Djavax.net.ssl.trustStore=clientTruststore.p12 -Djavax.net.ssl.trustStorePassword=passw0rd -cp ./com.ibm.mq.allclient-9.2.2.0.jar:./javax.jms-api-2.0.1.jar:. com.ibm.mq.samples.jms.JmsPut
java -Djavax.net.ssl.trustStore=clientTruststore.p12 -Djavax.net.ssl.trustStorePassword=passw0rd -cp .\com.ibm.mq.allclient-9.2.2.0.jar;.\javax.jms-api-2.0.1.jar;. com.ibm.mq.samples.jms.JmsPut
Congratuations, you've just sent you're first IBM MQ Message and you should see output similar to the following:
Sent message:
JMSMessage class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSDeliveryDelay: 0
JMSDeliveryTime: 1617186154396
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d512049424d5f4444435f514d202000476460013f0040
JMSTimestamp: 1617186154396
JMSCorrelationID: null
JMSDestination: queue:///DEV.QUEUE.1
JMSReplyTo: null
JMSRedelivered: false
JMSXAppID: JmsPutGet (JMS)
JMSXDeliveryCount: 0
JMSXUserID: app
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20210331
JMS_IBM_PutTime: 10223528
Your lucky number today is 369
SUCCESS