Before going to bed I thought to post this post. After couple days of struggling with IBM web sphere mq and other solutions on internet I could able to create a workable solution today… 🙂
In this post I’m going to tell you how to trigger simple c# console application when new message arrivals on MQ (IBM websphere MQ).
Lets say we have an queue manager called “TriggerTest” on 192.168.10.2 and it’s TCP listener port is 1436 and server – connection channel called “SVRCOMMUNICATION”.
In this queue manager we have an queue called “LocalQueue” and we want to invoke an application when new message comes to this queue.
So first of all to monitor this local queue we need to create an initiation queue. This must be type of SYSTEM.DEFAULT.INITIATION.QUEUE.
once you create the initiation queue , it looks like this
Then right click on the local queue and set these trigger properties. Process name is process definition “Process Name”. See the “Process Definition” image.
if you want to get more details on trigger types do visit this link http://www-01.ibm.com/support/docview.wss?uid=swg27015657&aid=1 . For the time being I’ll add these details.
- FIRST: A trigger event occurs when the current depth of the triggered queue changes from 0 to 1.
- EVERY: A trigger event occurs every time a message arrives on the triggered queue.
- DEPTH: A trigger event occurs when the number of messages on the triggered queue reaches the value of the TRIGDPTH attribute.
[taken from the above link]
Now right click on the Process Definitions and add new process. This is going to invoke our console application.
C# console application will read the local queue message and then writes that data in to a text file.
So far we have created initiation queue , process definition. But we need to get a service for monitoring this message communication. So we have to have monitor service.
There are two ways to start this monitor service. You can start monitor local queue from websphere server by using runmqtrm.exe . If you use your client machine then you need to use runmqtrc.exe. You can find these exe files on << IBM WebSphere Installation Directory>>/bin/
In this post I’m going to start runmqtmc.exe from command prompt (CMD).
SET MQSERVER=SVRCOMMUNICATION/TCP/192.168.10.2(1436)
runmqtmc -m TriggerTest -q InitQueue
once it successful
you can find more details from this link http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.dev.doc/q026970_.htm
Put a message on queue with your mq explorer client ,
When new message arrives this service will invoke c# console application and writes the message in to a text file.
Here is my C# console application code which will read mq and puts message in to queue
using IBM.WMQ; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConnectWithCCDT { class Program { static void Main(string[] args) { new Program().ConnectWithFiles(); } public void ConnectWithFiles() { MQQueueManager qm = null; Environment.SetEnvironmentVariable("MQCHLLIB", @"D:\MQCCDT\"); Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL.TAB"); try { Hashtable props = new Hashtable(); props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT); qm = new MQQueueManager("TriggerTest", props); MQQueue queue1 = qm.AccessQueue("LocalQueue", MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING); MQMessage message = new MQMessage(); queue1.Get(message); string queueMsg = message.ReadString(message.MessageLength); StreamWriter sw = new StreamWriter(@"D:\aa.txt", true); string data = queueMsg + " " + DateTime.Now.ToString(); sw.WriteLine(data); sw.Flush(); sw.Dispose(); Console.WriteLine("Message from Queueu {0}", data); queue1.Close(); qm.Disconnect(); Console.WriteLine("Success."); } catch (Exception ex) { Console.Write(ex); } } } }
I connected MQ with AMQCLCHL.TAB file. If you need more information please read my previous blog post https://2freeclear.wordpress.com/2014/11/05/ibm-websphere-mq-connection-with-ccdt-file/
Pingback: Advanced Message Security with IBM WebSphere MQ | Writing Wall
Reblogged this on Dinesh Ram Kali..
Hi Dinesh,
I am working on the same requirement. I have done the same steps mentioned above. Still MQ process not invoking c# program. Not sure what I am missing