【问题标题】:WebSphere MQ put message on topicWebSphere MQ 将消息放在主题上
【发布时间】:2015-04-30 07:38:04
【问题描述】:

我创建了一个小应用程序来订阅来自特定主题的消息。在我的测试环境中,我只有试用版 WebSphere MQ,我不知道如何将消息放入我确定的主题。我可以将消息放入队列并获取它,但是当我想从特定主题获取消息时,会得到一条空消息。

更新
将问题更新从 OP 的另一个答案移到问题中。

我使用示例代码C:\Program Files\IBM\WebSphere MQ\Tools\dotnet\samples\cs\base\SimpleSubscribe

// mq properties
            properties = new Hashtable();
            properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
            properties.Add(MQC.PORT_PROPERTY, port);
            properties.Add(MQC.CHANNEL_PROPERTY, channelName);
            #region pass
            properties.Add(MQC.USER_ID_PROPERTY, "LOGIN");
            properties.Add(MQC.PASSWORD_PROPERTY, "PASSWORD");
            #endregion
            properties.Add(MQC.MQCA_TOPIC_NAME, "News.Topic");

            if (sslKeyRepository != null)
            {
                properties.Add(MQC.SSL_CERT_STORE_PROPERTY, sslKeyRepository);
            }
            if (cipherSpec != null)
            {
                properties.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, cipherSpec);
            }
            if (sslPeerName != null)
            {
                properties.Add(MQC.SSL_PEER_NAME_PROPERTY, sslPeerName);
            }
            if (keyResetCount != 0)
            {
                properties.Add(MQC.SSL_RESET_COUNT_PROPERTY, keyResetCount);
            }
            if (sslCertRevocationCheck != false)
            {
                MQEnvironment.SSLCertRevocationCheck = sslCertRevocationCheck;
            }

            if (transportMode == "managed")
                properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
            else if (transportMode == "unmanaged")
                properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);

            // create connection
            Console.Write("Connecting to queue manager.. ");
            queueManager = new MQQueueManager(queueManagerName, properties);
            Console.WriteLine("done");

            // accessing topic
            Console.Write("Accessing topic " + topicName + ".. ");
            if (durability == "nondurable")
                topic = queueManager.AccessTopic(topicName, null, MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING);
            else if (durability == "durable")
                topic = queueManager.AccessTopic(topicName, null, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING | MQC.MQSO_DURABLE | MQC.MQSO_RESUME, null, "DurableSubscriptionName");
            Console.WriteLine("done");

            // creating a message object
            message = new MQMessage();
            message.WriteString(messageString);

            int time = 1;
            // getting messages continuously
            for (int i = 1; i <= numberOfMsgs; i++)
            {
                // creating a message object
                message = new MQMessage();

                try
                {
                    topic.Get(message);
                    Console.WriteLine("Message " + i + " got = " + message.ReadString(message.MessageLength));
                    message.ClearMessage();
                }
                catch (MQException mqe)
                {
                    if (mqe.ReasonCode == 2033)
                    {
                        ++time;
                        --i;
                        Console.WriteLine("No message available");
                        Thread.Sleep(1000);
                        //waiting for 10sec 
                        if (time > 10)
                        {
                            Console.WriteLine("Timeout : No message available");
                            break;
                        }
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
                    }
                }
            }

            // closing topic
            Console.Write("Closing topic.. ");
            topic.Close();
            Console.WriteLine("done");

            // disconnecting queue manager
            Console.Write("Disconnecting queue manager.. ");
            queueManager.Disconnect();
            Console.WriteLine("done");

【问题讨论】:

  • 信息不足。您使用的是 WebSphere Application Server 还是 WebSphere MQ?有哪些版本?您是使用 Java 还是 .net 访问?附上代码。
  • 您询问的所有信息都在标签中... C#,WebSphere MQ 版本 8.0.0.2 试用版
  • 如果您可以发布您的订阅方代码,那将会很有用。您使用 Base MQ .NET 还是 XMS .NET API?

标签: c# .net ibm-mq mq


【解决方案1】:

发布/订阅方法不同于放入队列和从队列中获取。为了接收已发布到某个主题的消息,接收应用程序必须订阅该主题。

如果你先创建一个订阅,然后从它接收消息,那么当你放入主题时,你的接收应用程序会得到消息的副本。

不过,我会重申 Shashi 的要求,请发布您目前拥有的代码,以便我们进一步提供帮助。

【讨论】:

    【解决方案2】:

    除了下面的代码,我看不出有什么问题。这条线既不会帮助也不会损害您的应用程序。该常量实际上用于 MQ 管理目的。你可以把它取下来。

     properties.Add(MQC.MQCA_TOPIC_NAME, "News.Topic");
    

    您是否有应用程序在使用以下方法创建订阅时针对指定的主题发布?

    topic = queueManager.AccessTopic(topicName,...
    

    如果没有人发布该主题,您的应用程序将不会收到任何发布。您的应用程序应该抛出一个MQRC 2033 - MQRC_NO_MESSAGE_AVAILABLE 异常并且不返回空消息。你没有遇到那个例外吗?当收到此异常时,应用程序将在控制台上打印“无可用消息”。你没看到吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 2010-09-21
      • 1970-01-01
      • 2011-05-29
      相关资源
      最近更新 更多