I'm trying to read off messages from a websphere mq queue and dump it in another queue.
Below is the code i have to do it
private void transferMessages()
{
MQQueueManager sqmgr = connectToQueueManager(S_SERVER_NAME, S_QMGR_NAME, S_PORT_NUMBER, S_CHANNEL_NAME);
MQQueueManager dqmgr = connectToQueueManager(D_SERVER_NAME, D_QMGR_NAME, D_PORT_NUMBER, D_CHANNEL_NAME);
if (sqmgr != null && dqmgr != null)
{
MQQueue sq = openSourceQueueToGet(sqmgr, S_QUEUE_NAME);
MQQueue dq = openDestQueueToPut(dqmgr, D_QUEUE_NAME);
if (sq != null && dq != null)
{
setPutMessageOptions();
setGetMessageOptions();
processMessages(sqmgr, sq, dqmgr, dq);
}
}
}
And I'm calling the above method in a for loop and creating separate threads as below.
int NO_OF_THREADS = 5;
Thread[] ts = new Thread[NO_OF_THREADS];
for (int i = 0; i < NO_OF_THREADS; i++)
{
ts[i] = new Thread(() => transferMessages());
ts[i].Start();
}
As you see, I'm making a fresh connection to the queue manager in the transferMessages method. Not sure for some reason, the program makes only one connection to MQ.
The custom method to connect to the queue manager is below..
private MQQueueManager connectToQueueManager(string MQServerName, string MQQueueManagerName, string MQPortNumber, string MQChannel)
{
try
{
mqErrorString = "";
MQQueueManager qmgr;
Hashtable mqProps = new Hashtable();
mqProps.Add(MQC.HOST_NAME_PROPERTY, MQServerName);
mqProps.Add(MQC.CHANNEL_PROPERTY, MQChannel);
mqProps.Add(MQC.PORT_PROPERTY, Convert.ToInt32(MQPortNumber));
mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
qmgr = new MQQueueManager(MQQueueManagerName, mqProps);
return qmgr;
}
catch (MQException mqex)
{
//catch and log MQException here
return null;
}
}
Any advise what am i missing?