/// <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)); } }
/// <summary> /// Get a message from an MQ Queue using a correlation id /// </summary> /// <param name="correlationId">correlation id</param> /// <returns>Response message</returns> public string GetMQResponseMessage(string correlationId) { MQMessage rsMsg = new MQMessage(); rsMsg.CorrelationId = HexaDecimalUtility.ConvertToBinary(correlationId); MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.Options = MQC.MQGMO_WAIT; gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID; gmo.WaitInterval = pollingTimeout; try { mqGetQueue.Get(rsMsg, gmo); return(rsMsg.ReadString(rsMsg.DataLength)); } catch (MQException mqe) { // Close Reponse Queue if still opened if (mqGetQueue.OpenStatus) { mqGetQueue.Close(); } // Close Queue manager if still opened if (mqQueueManager.OpenStatus) { mqQueueManager.Close(); } // Check if it a timeout exception if (MQAdapterErrorReasons.GetMQFailureReasonErrorCode(mqe.Reason) == "MQRC_NO_MSG_AVAILABLE") { throw new MQAdapterTimeoutException("Message with correlation Id " + correlationId + " Timed out"); } // MQ Exception throw new MQAdapterException("Error Code: " + MQAdapterErrorReasons.GetMQFailureReasonErrorCode(mqe.Reason)); } }