Beispiel #1
0
        private void ConsumeMessageXMS()
        {
            _mqHelper.Host          = txHost.Text;
            _mqHelper.Port          = Int32.Parse(txPort.Text);
            _mqHelper.QueueManager  = txQMgr.Text;
            _mqHelper.Channel       = txQChannel.Text;
            _mqHelper.ConsumerQueue = txQName.Text;
            _mqHelper.MQType        = MQXMSHelper.MQTypes.QUEUE;

            IConnectionFactory _mqConnectionFactory = _mqHelper.CreateMQConnectionFactoryWMQ();
            IConnection        _mqConnection        = _mqHelper.CreateMQConnection(_mqConnectionFactory);

            if (_mqConnection != null)
            {
                _mqConnection.Start();
            }
            ISession     _mqSession     = _mqHelper.CreateMQSession(_mqConnection);
            IDestination _mqDestination = _mqHelper.CreateMQDestination(_mqSession, _mqHelper.ConsumerQueue);

            _mqDestination.SetBooleanProperty(XMSC.WMQ_MQMD_READ_ENABLED, true);
            IMessageConsumer _mqConsumer = _mqHelper.CreateMQConsumer(_mqSession, _mqDestination);

            IMessage recvMsgObj = _mqConsumer.ReceiveNoWait();

            if (recvMsgObj != null)
            {
                txMessage.Text += _mqHelper.ConvertMessageObjectToString(recvMsgObj) + Environment.NewLine;
            }
            else
            {
                txMessage.Text += "No message consumed" + Environment.NewLine;
            }

            if (_mqHelper != null)
            {
                if (_mqConnection != null)
                {
                    _mqConnection.Stop();
                }
                _mqHelper.DestroyMQConsumer(_mqConsumer);
                _mqHelper.DestroyMQDestination(_mqDestination);
                _mqHelper.DestroyMQSession(_mqSession);
                _mqHelper.DestroyMQConnection(_mqConnection);

                _mqConnectionFactory = null;
            }
        }