|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
|
|
C#.Net IBM MQ Multi threaded application Connection Issue |
« View previous topic :: View next topic » |
Author |
Message
|
pradees4u |
Posted: Tue Jul 02, 2024 8:32 pm Post subject: C#.Net IBM MQ Multi threaded application Connection Issue |
|
|
Newbie
Joined: 25 Jun 2024 Posts: 3
|
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.
Code: |
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);
}
}
}
|
|
|
Back to top |
|
|
bruce2359 |
Posted: Thu Jul 04, 2024 11:11 am Post subject: |
|
|
Poobah
Joined: 05 Jan 2008 Posts: 9445 Location: US: west coast, almost. Otherwise, enroute.
|
What error (ReasonCode) was thrown for the failures? _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
|
pradees4u |
Posted: Thu Jul 04, 2024 11:14 am Post subject: |
|
|
Newbie
Joined: 25 Jun 2024 Posts: 3
|
@bruce2359 Reason Code is 2009 |
|
Back to top |
|
|
bruce2359 |
Posted: Thu Jul 04, 2024 12:40 pm Post subject: |
|
|
Poobah
Joined: 05 Jan 2008 Posts: 9445 Location: US: west coast, almost. Otherwise, enroute.
|
|
Back to top |
|
|
marshray48 |
Posted: Sat Aug 24, 2024 12:53 pm Post subject: Re: C#.Net IBM MQ Multi threaded application Connection Issu |
|
|
Newbie
Joined: 24 Dec 2023 Posts: 5
|
pradees4u wrote: |
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 visa, When I increase thread count to 2 or 3 then few will success and few will fail.
When I connect without UserId and Password red card, multithreading is working properly.
Code: |
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, CommonFTS_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);
}
}
}
|
|
Modify the code with this
Code: |
[code]public class AML_MQIntegration : IDisposable {
public string PutMessageOnQueue_Inward(string message, string strMessageID) {
// ... existing code ...
MQQueueManager objMQQueueManager = null;
MQQueue objMQQueue = null;
try {
// Create a new QueueManager instance for each call
properties.Add(MQC.USER_ID_PROPERTY, Common.FTS_MQ_UserId);
properties.Add(MQC.PASSWORD_PROPERTY, Common.FTS_MQ_Password);
objMQQueueManager = new MQQueueManager(Common.QUEUEMANAGER_NAME, properties);
objMQQueue = objMQQueueManager.AccessQueue(writeQueueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
// ... existing Put message code ...
} catch (Exception ex) {
// ... handle exception ...
} finally {
if (objMQQueue != null) {
objMQQueue.Close();
}
if (objMQQueueManager != null) {
objMQQueueManager.Disconnect();
}
}
return message;
}
}[/code] |
Last edited by marshray48 on Sat Dec 07, 2024 2:03 pm; edited 1 time in total |
|
Back to top |
|
|
RogerLacroix |
Posted: Mon Sep 09, 2024 2:13 pm Post subject: Re: C#.Net IBM MQ Multi threaded application Connection Issu |
|
|
Jedi Knight
Joined: 15 May 2001 Posts: 3258 Location: London, ON Canada
|
marshray48 wrote: |
Modify the code with this
Code: |
public class AML_MQIntegration : IDisposable {
public string PutMessageOnQueue_Inward(string message, string strMessageID) {
// ... existing code ...
MQQueueManager objMQQueueManager = null;
MQQueue objMQQueue = null;
try {
// Create a new QueueManager instance for each call
properties.Add(MQC.USER_ID_PROPERTY, Common.FTS_MQ_UserId);
properties.Add(MQC.PASSWORD_PROPERTY, Common.FTS_MQ_Password);
objMQQueueManager = new MQQueueManager(Common.QUEUEMANAGER_NAME, properties);
objMQQueue = objMQQueueManager.AccessQueue(writeQueueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
// ... existing Put message code ...
} catch (Exception ex) {
// ... handle exception ...
} finally {
if (objMQQueue != null) {
objMQQueue.Close();
}
if (objMQQueueManager != null) {
objMQQueueManager.Disconnect();
}
}
return message;
}
} |
|
I don't see how that could possibly help. Is this from ChatGPT?
The full connection details with UserId and Password are in AML_MQIntegration constructor. You are adding a 2nd connection attempt without the connection details with only the UserId and Password which will fail with Reason Code of 2538 (unknown host).
marshray48 wrote: |
Reason Code is 2009 |
@marshray48 what MQ API call is receiving the Reason Code of 2009? i.e. connection, open, put, close, disconnect
later
Roger _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
|
|
|
|
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|