ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » C#.Net IBM MQ Multi threaded application Connection Issue

Post new topic  Reply to topic
 C#.Net IBM MQ Multi threaded application Connection Issue « View previous topic :: View next topic » 
Author Message
pradees4u
PostPosted: Tue Jul 02, 2024 8:32 pm    Post subject: C#.Net IBM MQ Multi threaded application Connection Issue Reply with quote

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
View user's profile Send private message
bruce2359
PostPosted: Thu Jul 04, 2024 11:11 am    Post subject: Reply with quote

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
View user's profile Send private message
pradees4u
PostPosted: Thu Jul 04, 2024 11:14 am    Post subject: Reply with quote

Newbie

Joined: 25 Jun 2024
Posts: 3

@bruce2359 Reason Code is 2009
Back to top
View user's profile Send private message
bruce2359
PostPosted: Thu Jul 04, 2024 12:40 pm    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9445
Location: US: west coast, almost. Otherwise, enroute.

Looks like you posted the same thing in multi-phase commit . Please do not double post.

Looks like you posted the exact same question here https://stackoverflow.com/questions/78482012/c-net-ibm-mq-multi-threaded-application-connection-issue
Did you research mq reason code (mqrc) 2009? Did you follow any of the suggestions?
_________________
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
View user's profile Send private message
marshray48
PostPosted: Sat Aug 24, 2024 12:53 pm    Post subject: Re: C#.Net IBM MQ Multi threaded application Connection Issu Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Mon Sep 09, 2024 2:13 pm    Post subject: Re: C#.Net IBM MQ Multi threaded application Connection Issu Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » C#.Net IBM MQ Multi threaded application Connection Issue
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.