コード例 #1
0
 private void Reconnect(ref MQQueueManager queueManager, ref MQTopic topic, string topicName)
 {
     try
     {
         LogMsg(string.Format("开始重连MQ:{0},{1}", host, topicName));
         try
         {
             if (queueManager != null)
             {
                 queueManager.Disconnect();
             }
             if (topic != null)
             {
                 topic.Close();
             }
         }
         catch (Exception e)
         {
             LogMsg("释放连接失败" + e);
         }
         queueManager = new MQQueueManager(uri, properties);
         topic        = queueManager.AccessTopic(topicName, null,
                                                 MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING | MQC.MQSO_RESUME,
                                                 null, DurableSubscriptionName);
         LogMsg(string.Format("重连MQ成功:{0},{1}", host, topicName));
         if (ReconnectEvent != null)
         {
             ReconnectEvent(this.Tag, null);
         }
     }
     catch (Exception ex)
     {
         LogMsg(string.Format("重连MQ失败:host:{0},exp:{1}", host, ex));
     }
 }
コード例 #2
0
 public void OpenTopic_Ok()
 {
     using (var broker = MQQueueManager.Connect(QueueManagerName, 0, Channel, ConnectionInfo))
     {
         var topic = new MQTopic(broker, TopicName, string.Empty, MQC.MQTOPIC_OPEN_AS_PUBLICATION, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
         Assert.AreNotEqual(MQC.MQHC_UNUSABLE_HCONN, topic.Handle);
         Assert.AreNotEqual(MQC.MQHC_DEF_HCONN, topic.Handle);
         topic.Close();
     }
 }
コード例 #3
0
        private void UnsubscribeMessages()
        {
            if (subscriber != null)
            {
                subscriber.Close();
            }

            if (queueManager != null)
            {
                queueManager.Disconnect();
            }

            tmrSubscribe.Enabled = false;
        }
コード例 #4
0
        private void PublishMessage()
        {
            // txMessage.Text = "Publishing...";
            try
            {
                //_mqHelper.Host = txHost.Text;
                //_mqHelper.Port = Int32.Parse(txPort.Text);
                _mqHelper.QueueManager = txQMgr.Text;
                //_mqHelper.Channel = txQChannel.Text;
                _mqHelper.ProducerQueue = txQName.Text;
                //_mqHelper.MQType = MQXMSHelper.MQTypes.TOPIC;

                // option 1: WMQ
                // MQQueueManager queueManager = null;
                MQTopic   topic   = null;
                MQMessage message = null;
                string    msg     = txMessage.Text.ToString();

                Hashtable properties = new Hashtable();
                properties = new Hashtable();
                properties.Add(IBM.WMQ.MQC.HOST_NAME_PROPERTY, _mqHelper.Host);
                properties.Add(IBM.WMQ.MQC.PORT_PROPERTY, _mqHelper.Port);
                properties.Add(IBM.WMQ.MQC.CHANNEL_PROPERTY, _mqHelper.Channel);
                properties.Add(IBM.WMQ.MQC.TRANSPORT_PROPERTY, IBM.WMQ.MQC.TRANSPORT_MQSERIES_CLIENT); //unmanaged, or use TRANSPORT_MQSERIES_MANAGED

                // queueManager = new MQQueueManager(_mqHelper.QueueManager, properties);
                queueManager = new MQQueueManager(_mqHelper.QueueManager);
                // MessageBox.Show("Queue Manager created as:" + Environment.NewLine + "Host:" + _mqHelper.Host + Environment.NewLine + "Port:" + _mqHelper.Port + Environment.NewLine + "Channel:" + _mqHelper.Channel + Environment.NewLine + "Queue Manager:" + _mqHelper.QueueManager);
                // MessageBox.Show("Queue Manager created!");
                // Note: API signiture is confusing, the 1st parameter of AccessTopic is actually Topic String, NOT Topic Name
                topic = queueManager.AccessTopic(_mqHelper.ProducerQueue, null, IBM.WMQ.MQC.MQTOPIC_OPEN_AS_PUBLICATION, IBM.WMQ.MQC.MQOO_OUTPUT + IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING);
                // topic = queueManager.AccessTopic(_mqHelper.ConsumerQueue, null, IBM.WMQ.MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, IBM.WMQ.MQC.MQSO_CREATE | IBM.WMQ.MQC.MQSO_FAIL_IF_QUIESCING | IBM.WMQ.MQC.MQSO_MANAGED | IBM.WMQ.MQC.MQSO_DURABLE);
                // topic = new MQTopic(queueManager, "TEST1", null, IBM.WMQ.MQC.MQTOPIC_OPEN_AS_PUBLICATION, IBM.WMQ.MQC.MQSO_CREATE + IBM.WMQ.MQC.MQSO_FAIL_IF_QUIESCING);

                message = new MQMessage();
                message.WriteString(msg);
                // MQPutMessageOptions mqpo = new MQPutMessageOptions();
                topic.Put(message);
                // queueManager.Put(IBM.WMQ.MQC.MQOT_TOPIC, null, _mqHelper.QueueManager, _mqHelper.ProducerQueue, message);
                MessageBox.Show("Message " + message.MessageLength + " published to " + _mqHelper.ProducerQueue);

                topic.Close();
                //MessageBox.Show(MQEnvironment.properties.Count + "");
                queueManager.Disconnect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.Source + Environment.NewLine + ex.GetBaseException());
            }
        }