When I connect to IBM MQ QueueManager using multi-threading, it does not connect all of the requests to MQ. Few connect and few fail. If I use thread count as 1 then all the request are connected. When I increase thread count to 2 or 3 then few will success and few will fail.
Iam using below code in C#.
public string PutMessageOnQueue_Inward(string message, string strMessageID)
{
string writeQueueName = Common.WRITE_MESSAGE_QUEUENAME_INWARD;
try
{
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, Common.FTS_MQ_HostName);
properties.Add(MQC.CHANNEL_PROPERTY, Common.QUEUE_CHANNEL);
properties.Add(MQC.PORT_PROPERTY, Common.FTS_MQ_Port);
properties.Add(MQC.USER_ID_PROPERTY, Common.FTS_MQ_UserId);
properties.Add(MQC.PASSWORD_PROPERTY, Common.FTS_MQ_Password);
properties.Add(MQC.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
using (var objMQQueueManager = new MQQueueManager(Common.QUEUEMANAGER_NAME, properties))
{
using (var objMQQueue = objMQQueueManager.AccessQueue(writeQueueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING))
{
var objPutMQMessage = new MQMessage
{
//UTF-8 character encoding
CharacterSet = 1208,
Format = MQC.MQFMT_STRING,
MessageType = MQC.MQMT_DATAGRAM,
Report = MQC.MQRO_NONE,
};
objPutMQMessage.WriteString(message);
objMQQueue.Put(objPutMQMessage);
objMQQueueManager.Commit();
objMQQueue.Close();
objMQQueueManager.Disconnect();
}
}
}
catch (MQException mqEx)
{
message = null;
}
catch (Exception ex)
{
message = null;
}
return message;
}