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.
When I connect without UserId and Password, multithreading is working properly.
public class AML_MQIntegration : IDisposable
{
#region Decalrations
MQQueue objMQQueue;
MQMessage objPutMQMessage;
MQMessage objReadMQMessage;
MQQueueManager objMQQueueManager;
public AML_MQIntegration()
{
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);
Common.WriteFTSLog("HOST_NAME_PROPERTY " + Common.FTS_MQ_HostName + Environment.NewLine);
Common.WriteFTSLog("CHANNEL_PROPERTY " + Common.QUEUE_CHANNEL + Environment.NewLine);
Common.WriteFTSLog("PORT_PROPERTY " + Common.FTS_MQ_Port + Environment.NewLine);
objMQQueueManager = new MQQueueManager(Common.QUEUEMANAGER_NAME, properties);
}
public string PutMessageOnQueue_Inward(string message, string strMessageID)
{
//bool isSuccess = true;
string writeQueueName = Common.WRITE_MESSAGE_QUEUENAME_INWARD;
try
{
objMQQueue = objMQQueueManager.AccessQueue(writeQueueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
objPutMQMessage = new MQMessage();
//UTF-8 character encoding
objPutMQMessage.CharacterSet = 1208;
objPutMQMessage.WriteString(message);
objPutMQMessage.Format = MQC.MQFMT_STRING;
objPutMQMessage.MessageType = MQC.MQMT_DATAGRAM;
objPutMQMessage.Report = MQC.MQRO_NONE;
objMQQueue.Put(objPutMQMessage);
objMQQueueManager.Commit();
if (objMQQueue.OpenStatus)
{
objMQQueue.Close();
}
}
catch (Exception ex)
{
//LogMQ("Error while putting message in to MQ ," + ex.Message + " " + ex.StackTrace, "MQ_Error_");
Common.WriteFTSLog("Exception for PutMessageOnQueue_Inward strMessageID:" + strMessageID + Environment.NewLine + ex.Message + ex.StackTrace);
//isSuccess = false;
message = null;
}
finally
{
objMQQueue.Close();
objMQQueueManager.Disconnect();
}
//return isSuccess;
return message;
}
}
public void ProcessInwardInstCovAMLRequestSendProcess(AMLRequestDetails AmlRequestDetail)
{
DAL_InwardAMLProcess objDAL_AMLDetails = new DAL_InwardAMLProcess();
string Error = string.Empty;
using (AML_MQIntegration objMQIntegration = new AML_MQIntegration())
{
try
{
if (!string.IsNullOrEmpty(AmlRequestDetail.Request))
{
string XMLSend = objMQIntegration.PutMessageOnQueue_Inward(AmlRequestDetail.Request, AmlRequestDetail.AmlSRQId.ToString());
if (!string.IsNullOrEmpty(XMLSend))
{
if (objDAL_AMLDetails.UpdateAMLScreeningRequestInstCov(AmlRequestDetail.AmlSRQId, "U", ref Error))
Common.WriteFTSLog("Successfully Saved Inward AML Request Send status for Inward AML Request Id: " + AmlRequestDetail.AmlSRQId);
else
Common.WriteFTSLog("Failed Saving Inward AML Request Send status for Inward AML Request Id: " + AmlRequestDetail.AmlSRQId);
}
else
{
Common.WriteFTSLog("Failed during Request Send for Inward AML Request Id: " + AmlRequestDetail.AmlSRQId);
objDAL_AMLDetails.UpdateAMLScreeningRequestInstCov(AmlRequestDetail.AmlSRQId, "E", ref Error);
}
}
}
catch (Exception ex)
{
Common.WriteFTSLog("Exception occured during Request Send for Inward AML Request Id: " + AmlRequestDetail.AmlSRQId + " " + ex.Message.ToString() + ex.StackTrace);
objDAL_AMLDetails.UpdateAMLScreeningRequestInstCov(AmlRequestDetail.AmlSRQId, "E", ref Error);
Common.handleErrorLogInService(ex);
}
}
}