In the first blog post we saw how to deploy MQ into IBM Cloud Private. We deployed MQ which created a set of kubernetes resources such as pod, services, statefulsets and a queue manager named “mqdemo2”. In this blog post lets see how to connect to the pod (mqdemo2-ibm-mq-0) outside the cluster and how to connect to the queue manager, put and get messages.
kubectl get all -l release=mqdemo2 shows all the resources deployed by MQ
kubectl get all -l release=mqdemo2 NAME DESIRED CURRENT AGE statefulsets/mqdemo2-ibm-mq 1 1 2d NAME READY STATUS RESTARTS AGE po/mqdemo2-ibm-mq-0 1/1 Running 0 2d NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/mqdemo2-ibm-mq NodePort 10.0.0.158
"mqdemo2-ibm-mq-0" is the name of the pod and "svc/mqdemo2-ibm-mq" is the name of the service deployed with two ports 1414 and 9443 for the mqchannel and mqwebconsole respectively.
Pods in kubernetes are not exposed outside the cluster without a service.
kubectl expose pod command will let you to expose the pod outside. It creates a service for each of the two ports that we want to access outside.
kubectl expose pod mqdemo2-ibm-mq-0 --port 30455 --name mqchannel --type NodePort kubectl expose pod mqdemo2-ibm-mq-0 --port 30899 --name mqwebconsole --type NodePort
Having created the service you now need to look up the port numbers that have been allocated to the "NodePort" using the
kubectl get all -l release=mqdemo2 command. In the example below the mqchannel is exposed publicly on port 31915 and the mqwebconsole on port 30998.
kubectl get all -l release=mqdemo2 NAME DESIRED CURRENT AGE statefulsets/mqdemo2-ibm-mq 1 1 2d NAME READY STATUS RESTARTS AGE po/mqdemo2-ibm-mq-0 1/1 Running 0 2d NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/mqchannel NodePort 10.0.0.63
30455:31915/TCP 2d svc/mqdemo2-ibm-mq NodePort 10.0.0.158 1414:30455/TCP,9443:30899/TCP 2d svc/mqwebconsole NodePort 10.0.0.100 30899:30998/TCP 2d
MQ Web console can now be accessed using the URL â€śhttps://MasterNodeIP:30998/ibmmq/console/â€ť. Log in by typing admin for the user name and password that you provided while deploying MQ. Following figure shows the MQ Web console with a queue manager named "mqdemo2" and other default object that got created while deploying MQ. Using the MQ Web console the queue manager â€śmqdemo2â€ť can be administered and messages put or retrieved from the queue using the Queue widget.
Following figure shows the MQ Web Console after I have created a queue named â€śQ1â€ť and svrconn channel named "mqdemo2_svrconn".
Now lets see how to put a messages using a client application to the queue â€śQ1â€ť of queue manager â€śmqdemo2â€ť using the svrconn channel â€śmqdemo2_svrconnâ€ť.
set the environment variable "MQSERVER" using the â€śmqdemo2_svrconnâ€ť channel and the exposed mqchannel port 31915 in the client system.
The channel authentication, connection authentication and authority on the objects have to be set appropriately for the client application to put and get message to the queue "Q1". Use sample applications amqsputc and amqsgetc from the client machine to put and retrieve a message into and from the queue â€śQ1â€ť of â€śmqdemo2â€ť queue manager running inside the pod.
amqsputc Q1 mqdemo2 Sample AMQSPUT0 start target queue is Q1 This is a test message Sample AMQSPUT0 end
amqgetc Q1 mqdemo2 Sample AMQSGET0 start message
no more messages Sample AMQSGET0 end
We have now seen how to connect to the pod and use the queue manager created by the MQ Helm charts.