2538 - MQRC_HOST_NOT_AVAILABLE

2019-07-10 04:20发布

I am new to IBM Websphere MQ

I am trying add messages to a Remote websphere MQ queue manager. I am getting following error while trying to connect to it.

Also, I have tried many possible solutions provided in forums like changing .net framework to 3.5 also I am getting good ping while I ping the remote machine but I am unable to connect to it using C# code. The queue manager listener is up and running, but this is the error I am getting

2538 - MQRC_HOST_NOT_AVAILABLE

while trying to do this.

queueManager = new MQQueueManager();

I am using .net framework 4.5. Any help would be appreciated.

标签: .net ibm-mq
3条回答
戒情不戒烟
2楼-- · 2019-07-10 05:14

Problem description:
O/S: 7.3, MQ version: 8.0.0.5. The server is in a Enclave.

A queue manager exists with a Server-connection channel named
CL_IR360. The user is trying to connect to it, however, it is failing
with the below error.

Error message user is getting:

  • Test Connection Failure
  • Connection to host 'ip address(port)' rejected
  • JmqiException CC=2 RC=2538 AMQ9213
  • A communications error for TCP occurred
  • java.net.SocketTimeoutException - connect timed out
  • Connection to host ip address(port) rejected
  • MQxx HOST NOT AVAILABLE 2538

The error above in this particular case was due to the fact that there was no channel authority (SET CHLAUTH) setting to the Server-connection channel. A channel authority was added and the error was resolved.

查看更多
聊天终结者
3楼-- · 2019-07-10 05:19

MQRC_HOST_NOT_AVAILABLE could mean that your client is unable to find the Queue Manager you have told it to look for. Given that you have said your code is

queueManager = new MQQueueManager();

I suspect you haven't told your .NET some key bits of information it needs to know to be able to find the Queue Manager. In order to connect a MQ Client to a Queue Manager, it needs to know the

  • channel to connect into
  • Hostname of the machine running the Queue Manager
  • Port that the Queue manager is running on

For .NET these can be supplied in different ways which are detailed in the knowledge center doc on the MQQueueManager class.

From that page the example code to connect to a Queue Manager says:

MQEnvironment.hostname = "fred.mq.com"; // host to connect to

MQEnvironment.port = -1; // port to connect to. If not set, this defaults to 1414 for WebSphereMQ Client connections.

MQEnvironment.channel = "channel.name"; // the CASE-SENSITIVE name of the SVRCONN channel on the queue manager

MQQueueManager qMgr = new MQQueueManager("MYQM");

Also note that the call to create a MQQueueManager also takes a parameter which is the name of the Queue Manager connecting to.

Check that you are providing all of the necessary information that a client needs to connect including the name of the Queue Manager. If it is still failing then the check the Queue Manager's logs for any error messages (if there are none the Client really isn't getting to the Queue Manager otherwise the error message will say why the Queue Manager isn't responding)

查看更多
淡お忘
4楼-- · 2019-07-10 05:20

Please do not use MQEnvironment class as it is not thread safe. It is far better to put all the information in a Hashtable and pass the Hashtable to the MQQueueManager class. Here is a MQ .NET managed-mode example using a Hashtable for MQ connection information:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using IBM.WMQ;

namespace MQTest02
{
   class MQTest02
   {
      private Hashtable inParms = null;
      private Hashtable qMgrProp = null;
      private System.String qManager;
      private System.String outputQName;

      /*
      * The constructor
      */
      public MQTest02()
         : base()
      {
      }

      /// <summary> Make sure the required parameters are present.</summary>
      /// <returns> true/false
      /// </returns>
      private bool allParamsPresent()
      {
         bool b = inParms.ContainsKey("-h") && inParms.ContainsKey("-p") &&
                  inParms.ContainsKey("-c") && inParms.ContainsKey("-m") &&
                  inParms.ContainsKey("-q");
         if (b)
         {
            try
            {
               System.Int32.Parse((System.String)inParms["-p"]);
            }
            catch (System.FormatException e)
            {
               b = false;
            }
         }

         return b;
      }

      /// <summary> Extract the command-line parameters and initialize the MQ variables.</summary>
      /// <param name="args">
      /// </param>
      /// <throws>  IllegalArgumentException </throws>
      private void init(System.String[] args)
      {
         inParms = Hashtable.Synchronized(new Hashtable());
         if (args.Length > 0 && (args.Length % 2) == 0)
         {
            for (int i = 0; i < args.Length; i += 2)
            {
               inParms[args[i]] = args[i + 1];
            }
         }
         else
         {
            throw new System.ArgumentException();
         }

         if (allParamsPresent())
         {
            qManager = ((System.String)inParms["-m"]);
            outputQName = ((System.String)inParms["-q"]);

            qMgrProp = new Hashtable();
            qMgrProp.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

            qMgrProp.Add(MQC.HOST_NAME_PROPERTY, ((System.String)inParms["-h"]));
            qMgrProp.Add(MQC.CHANNEL_PROPERTY, ((System.String)inParms["-c"]));

            try
            {
               qMgrProp.Add(MQC.PORT_PROPERTY, System.Int32.Parse((System.String)inParms["-p"]));
            }
            catch (System.FormatException e)
            {
               qMgrProp.Add(MQC.PORT_PROPERTY, 1414);
            }

            if (inParms.ContainsKey("-u"))
               qMgrProp.Add(MQC.USER_ID_PROPERTY, ((System.String)inParms["-u"]));

            if (inParms.ContainsKey("-x"))
               qMgrProp.Add(MQC.PASSWORD_PROPERTY, ((System.String)inParms["-x"]));

            if (inParms.ContainsKey("-s"))
               qMgrProp.Add(MQC.SECURITY_EXIT_PROPERTY, ((System.String)inParms["-s"]));

            System.Console.Out.WriteLine("MQTest02:");
            Console.WriteLine("  QMgrName ='{0}'", qManager);
            Console.WriteLine("  Output QName ='{0}'", outputQName);

            System.Console.Out.WriteLine("QMgr Property values:");
            foreach (DictionaryEntry de in qMgrProp)
            {
               Console.WriteLine("  {0} = '{1}'", de.Key, de.Value);
            }
         }
         else
         {
            throw new System.ArgumentException();
         }
      }

      /// <summary> Connect, open queue, read a message, close queue and disconnect.
      ///
      /// </summary>
      /// <throws>  MQException </throws>
      private void testReceive()
      {
         MQQueueManager qMgr = null;
         MQQueue queue = null;
         int openOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;
         MQGetMessageOptions gmo = new MQGetMessageOptions();
         MQMessage receiveMsg = null;

         try
         {
            qMgr = new MQQueueManager(qManager, qMgrProp);
            System.Console.Out.WriteLine("MQTest02 successfully connected to " + qManager);

            queue = qMgr.AccessQueue(outputQName, openOptions, null, null, null); // no alternate user id
            System.Console.Out.WriteLine("MQTest02 successfully opened " + outputQName);

            receiveMsg = new MQMessage();

            queue.Get(receiveMsg, gmo);
            System.Console.Out.WriteLine("Message Data>>>" + receiveMsg.ReadString(receiveMsg.MessageLength));
         }
         catch (MQException mqex)
         {
            System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
         }
         catch (System.IO.IOException ioex)
         {
            System.Console.Out.WriteLine("MQTest02 ioex=" + ioex);
         }
         finally
         {
            try
            {
               queue.Close();
               System.Console.Out.WriteLine("MQTest02 closed: " + outputQName);
            }
            catch (MQException mqex)
            {
               System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
            }
            try
            {
               qMgr.Disconnect();
               System.Console.Out.WriteLine("MQTest02 disconnected from " + qManager);
            }
            catch (MQException mqex)
            {
               System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
            }
         }
      }

      /// <summary> main line</summary>
      /// <param name="args">
      /// </param>
      //        [STAThread]
      public static void Main(System.String[] args)
      {
         MQTest02 mqt = new MQTest02();

         try
         {
            mqt.init(args);
            mqt.testReceive();
         }
         catch (System.ArgumentException e)
         {
            System.Console.Out.WriteLine("Usage: MQTest02 -h host -p port -c channel -m QueueManagerName -q QueueName [-u userID] [-x passwd] [-s securityExit]");
            System.Environment.Exit(1);
         }
         catch (MQException e)
         {
            System.Console.Out.WriteLine(e);
            System.Environment.Exit(1);
         }

         System.Environment.Exit(0);
      }
   }
}
查看更多
登录 后发表回答