示例#1
0
        /// <summary>
        /// Puts a message in an MQ Queue using the user Id provided
        /// <param name="message">The message to be put in the queue</param>
        /// <returns>Response message</returns>
        /// </summary>
        public string PushMQRequestMessage(string message)
        {
            try
            {
                MQMessage requestMessage = new MQMessage();

                requestMessage.Persistence = 0;

                requestMessage.ReplyToQueueName        = mqResponseQueueName;
                requestMessage.ReplyToQueueManagerName = mqQueueManagerName;

                requestMessage.Format        = MQC.MQFMT_STRING;
                requestMessage.CharacterSet  = characterSet;
                requestMessage.MessageType   = MQC.MQMT_REQUEST;
                requestMessage.MessageId     = HexaDecimalUtility.ConvertToBinary(GenerateMQMsgId());
                requestMessage.CorrelationId = requestMessage.MessageId;

                MQPutMessageOptions pmo = new MQPutMessageOptions();
                pmo.Options = MQC.MQPMO_SET_IDENTITY_CONTEXT;

                requestMessage.WriteString(message);

                mqPutQueue.Put(requestMessage, pmo);

                string _msgId = BinaryUtility.ConvertToHexaDecimal(requestMessage.MessageId);

                return(_msgId);
            }
            catch (MQException mqe)
            {
                // Close request Queue if still opened
                if (mqPutQueue.OpenStatus)
                {
                    mqPutQueue.Close();
                }
                // Close Queue manager if still opened
                if (mqQueueManager.OpenStatus)
                {
                    mqQueueManager.Close();
                }

                throw new MQAdapterException("Error Code: " +
                                             MQAdapterErrorReasons.GetMQFailureReasonErrorCode(mqe.Reason));
            }
        }