Exemple #1
0
        private bool sendMessage(string queueName, int requestId, MQQueue queue, MQQueueManager manager, string messageId, string message, string correlationId, Object lockObject)
        {
            lock (lockObject)
            {
                bool sentMessage = false;
                try
                {
                    MQPutMessageOptions pmo = new MQPutMessageOptions();
                    pmo.Options = MQC.MQOO_INQUIRE | MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQPMO_SYNCPOINT;
                    MQMessage mqMessage = new MQMessage();
                    mqMessage.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(message));
                    mqMessage.Format        = MQC.MQFMT_STRING;
                    mqMessage.MessageId     = System.Text.ASCIIEncoding.ASCII.GetBytes(messageId);
                    mqMessage.CorrelationId = System.Text.ASCIIEncoding.ASCII.GetBytes(correlationId);
                    queue.Put(mqMessage, pmo);


                    manager.Commit();
                    sentMessage = true;
                    LogUtil.logInfo("Sent message " + requestId + " to " + queueName);
                    LogUtil.logInfo("End SendMesage:");
                }
                catch (MQException e)
                {
                    sentMessage = false;
                    manager.Backout();
                    LogUtil.log("Error sending the message to  " + queue.Name + " queue", e);
                }
                return(sentMessage);
            }
        }
Exemple #2
0
        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="queueName">队列名称</param>
        /// <param name="sendMessages">发送内容</param>
        public void SendMessages(string queueName, string sendMessages)
        {
            MQQueueManager sQMgr   = null; //发送消息的队列管理器
            MQQueue        remoteQ = null; //发送消息的队列

            try
            {
                // 创建一个连接到队列管理器
                sQMgr = new MQQueueManager(queueManagerName, ConnProperties);

                //现在指定要打开的队列,
                //和打开选项…
                remoteQ = sQMgr.AccessQueue(queueName, MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INQUIRE);

                // 定义一个简单的WebSphere MQ消息
                MQMessage putMessage = new MQMessage();

                putMessage.WriteString(sendMessages);

                // 指定消息选项…
                MQPutMessageOptions pmo = new MQPutMessageOptions();

                // 放入消息到队列
                remoteQ.Put(putMessage, pmo);

                remoteQ.Close();    //关闭队列
                sQMgr.Disconnect(); //关闭队列管理器连接
            }
            catch
            {
            }
        }
Exemple #3
0
        public bool PutMessage(string queueName, string message)
        {
            bool    success = false;
            MQQueue queue   = null;

            try
            {
                //eventLog1.WriteEntry("Accessing queue {0}", queueName);
                queue = _queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                MQMessage queueMessage = new MQMessage();
                queueMessage.CharacterSet = 1208;  // force to UTF-8 for InService
                queueMessage.WriteString(message);
                queueMessage.Format = MQC.MQFMT_STRING;
                MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);

                success = true;
            }
            catch (MQException mqe)
            {
                success = false;
                //eventLog1.WriteEntry("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
                //throw new Exception(string.Format("Error writing to {0} queue", queueName));
            }
            finally
            {
                if (queue != null)
                {
                    //eventLog1.WriteEntry("Closing queue");
                    queue.Close();
                }
            }
            return(success);
        }
Exemple #4
0
        public string WriteMsg(string strInputMsg)
        {
            string strReturn = "";

            try
            {
                queue = queueManager.AccessQueue(QueueName,
                                                 MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                message      = strInputMsg;
                queueMessage = new MQMessage();
                queueMessage.WriteString(message);
                queueMessage.Format    = MQC.MQFMT_STRING;
                queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);
                strReturn = "Message sent to the queue successfully";
            }
            catch (MQException MQexp)
            {
                strReturn = "Exception: " + MQexp.Message;
            }
            catch (Exception exp)
            {
                strReturn = "Exception: " + exp.Message;
            }
            return(strReturn);
        }
Exemple #5
0
        /// <summary>
        /// Puts a message object in the queue.
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="message"></param>
        private void PutRequestMessage(string connectionKeyName, MQMessage message)
        {
            MQQueue queue = null;

            try
            {
                if (!IsConnected)
                {
                    Connect(connectionKeyName);
                }

                MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
                queue = _queueManager.AccessQueue(_activeConnection.RequestQueue, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                queue.Put(message, queuePutMessageOptions);
            }
            catch (MQException mqe)
            {
                _log.ErrorFormat("Exception in PutRequestMessage(). Message: {0}", mqe.Message);
            }
            finally
            {
                if (queue != null)
                {
                    queue.Close();
                }
            }
        }
        public void SendMQ(string xm)
        {
            string messageXML = xm;
            bool   sent       = false;
            int    tries      = 1;

            lock (sendLock) {
                try {
                    using (MQQueueManager queueManager = new MQQueueManager(qMgr, connectionParams)) {
                        var     openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
                        MQQueue queue       = queueManager.AccessQueue(queueName, openOptions);
                        var     message     = new MQMessage {
                            CharacterSet = 1208 // UTF-8
                        };
                        message.WriteString(messageXML);
                        message.Format = MQC.MQFMT_STRING;
                        MQPutMessageOptions putOptions = new MQPutMessageOptions();
                        queue.Put(message, putOptions);
                        queue.Close();
                        sent = true;
                        logger.Trace($"===Message Sent to {queueName}");
                    }
                } catch (Exception ex) {
                    tries++;
                    logger.Info(ex.Message);
                    logger.Info("Error send MQ Message");
                }
                if (!sent)
                {
                    logger.Trace($"===Message NOT Sent to  {queueName}");
                }
            }
        }
Exemple #7
0
        string sendMessage(string message, string queueName)
        {
            try
            {
                queue = qMgr.AccessQueue(queueName, MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_SHARED | MQC.MQOO_INQUIRE);
            }
            catch (MQException e)
            {
                return("打开队列失败:" + e.Message);
            }
            var mqMsg = new MQMessage();

            mqMsg.WriteString(message);
            var putOptions = new MQPutMessageOptions();

            try
            {
                queue.Put(mqMsg, putOptions);
                return("消息放置完毕");
            }
            catch (MQException mqe)
            {
                return("发送异常终止:" + mqe.Message);
            }
            finally
            {
                try
                {
                    qMgr.Disconnect();
                }
                catch (MQException e)
                {
                }
            }
        }
Exemple #8
0
        public bool PutMessage(string queueName, string message)
        {
            bool    success = false;
            MQQueue queue   = null;

            try
            {
                _log.DebugFormat("Accessing queue {0}", queueName);
                queue = _queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                MQMessage queueMessage = new MQMessage();
                queueMessage.CharacterSet = 1208;  // force to UTF-8 for InService
                queueMessage.WriteString(message);
                queueMessage.Format = MQC.MQFMT_STRING;
                MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);

                success = true;
            }
            catch (MQException mqe)
            {
                success = false;
                _log.ErrorFormat("MQHelper::MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
            }
            finally
            {
                if (queue != null)
                {
                    _log.Debug("MQHelper::PutMessage() - Closing queue...");
                    queue.Close();
                }
            }
            return(success);
        }
Exemple #9
0
        /// <summary>
        /// Write Message to Local Queue
        /// </summary>
        /// <param name="strInputMsg">Text Message</param>
        /// <param name="strqueueName">Queue Name</param>
        /// <returns></returns>
        public MQMessageStatus WriteLocalQMsg(string strInputMsg, string strQueueName)
        {
            MQMessageStatus messageStatus = new MQMessageStatus();
            string          strReturn     = string.Empty;

            SendQueueName = strQueueName;
            try
            {
                queue = queueManager.AccessQueue(SendQueueName,
                                                 MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                message      = strInputMsg;
                queueMessage = new MQMessage();
                queueMessage.WriteString(message);
                queueMessage.Format    = MQC.MQFMT_STRING;
                queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);
                strReturn = "Message sent to the queue successfully";

                messageStatus.Message = strReturn;
                messageStatus.Status  = true;
            }
            catch (MQException MQexp)
            {
                strReturn             = "Exception: " + MQexp.Message;
                messageStatus.Message = strReturn;
                messageStatus.Status  = false;
            }
            catch (Exception exp)
            {
                strReturn             = "Exception: " + exp.Message;
                messageStatus.Message = strReturn;
                messageStatus.Status  = false;
            }
            return(messageStatus);
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="applicationIdData"></param>
        /// <param name="expiry"></param>
        /// <param name="priority"></param>
        public void Put(string message, string applicationIdData = null, int?expiry = null, int?priority = null)
        {
            var mqMsg = new MQMessage();

            mqMsg.WriteString(message);

            mQQueue.Put(mqMsg);
        }
Exemple #11
0
        public async Task <ExchangeMessage> SendMqStuff(ExchangeMessage xm)
        {
            await Task.Run(() => { });

            string messageXML = xm.payload;
            bool   sent       = false;
            int    tries      = 1;

            lock (sendLock)
            {
                do
                {
                    if (tries > maxRetry && maxRetry > 0)
                    {
                        xm.sent   = false;
                        xm.status = $"Exceeded Connection retries on MQ {queueName}";
                        return(xm);
                    }

                    try
                    {
                        using (MQQueueManager queueManager = new MQQueueManager(qMgr, connectionParams))
                        {
                            var     openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
                            MQQueue queue       = queueManager.AccessQueue(queueName, openOptions);
                            var     message     = new MQMessage
                            {
                                CharacterSet = 1208 // UTF-8
                            };
                            message.WriteString(messageXML);
                            message.Format = MQC.MQFMT_STRING;
                            MQPutMessageOptions putOptions = new MQPutMessageOptions();
                            queue.Put(message, putOptions);
                            queue.Close();
                            sent = true;
                            logger.Trace($"===Message Sent {xm.uuid} to {queueName}");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!isLogger)
                        {
                            logger.Info("Unable to send message to : " + queueName + " : " + ex.Message);
                        }
                        tries++;
                    }
                    if (!sent)
                    {
                        logger.Trace($"===Message NOT Sent {xm.uuid} to  {queueName}");
                    }
                } while (!sent);
            }
            xm.sent   = true;
            xm.status = $"Sent to  MQ {queueName}";

            return(xm);
        }
Exemple #12
0
        /// <summary>
        /// send a given queue message through the given queue
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="qMessage"></param>
        /// <returns></returns>
        public bool SendMessage(MQQueue queue, MQMessage qMessage)
        {
            bool sentFlag = false;
            MQPutMessageOptions msgOptions = new MQPutMessageOptions();

            queue.Put(qMessage, msgOptions);
            sentFlag = true;

            return(sentFlag);
        }
Exemple #13
0
        protected MQMessage[] Send(int command, PCFParameter[] parameters)
        {
            if (parameters == null)
            {
                throw new Exception("Must specify parameters!");
            }
            MQQueue   queue   = this.qMgr.AccessQueue("SYSTEM.DEFAULT.MODEL.QUEUE", 0x2021);
            MQMessage message = new MQMessage();

            message.ReplyToQueueName = queue.Name;
            message.MessageType      = 1;
            message.Feedback         = 0;
            message.Format           = "MQADMIN ";
            message.Report           = 0;
            MQCFH.Write(message, command, parameters.Length);
            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i].Write(message);
            }
            MQQueue             queue2 = this.qMgr.AccessQueue(this.qMgr.CommandInputQueueName, 0x2030);
            MQPutMessageOptions pmo    = new MQPutMessageOptions();

            pmo.Options = 0x40;
            queue2.Put(message, pmo);
            MQGetMessageOptions gmo = new MQGetMessageOptions();

            gmo.Options      = 0x2001;
            gmo.WaitInterval = this.waitInterval;
            gmo.MatchOptions = 2;
            ArrayList list     = new ArrayList();
            MQMessage message2 = null;
            int       compCode = 0;
            int       reason   = 0;
            int       num4     = 1;

            do
            {
                message2 = new MQMessage();
                message2.CorrelationId = message.MessageId;
                queue.Get(message2, gmo);
                message2.SkipBytes(20);
                num4     = message2.ReadInt4();
                compCode = message2.ReadInt4();
                reason   = message2.ReadInt4();
                message2.Seek(0);
                if (compCode != 0)
                {
                    throw new PCFException(compCode, reason);
                }
                list.Add(message2);
            }while (num4 == 0);
            queue2.Close();
            queue.Close();
            return((MQMessage[])list.ToArray(typeof(MQMessage)));
        }
Exemple #14
0
        public void Put(string queueName, MQMessage message)
        {
            MQQueue             mqQueue           = _mqQueueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            MQPutMessageOptions putMessageOptions = new MQPutMessageOptions();

            putMessageOptions.Options += MQC.MQGMO_SYNCPOINT;

            mqQueue.Put(message, putMessageOptions);

            mqQueue.Close();
        }
Exemple #15
0
        public void OnNext(MQMessage value)
        {
            if (queue == null || queueManager == null || !queueManager.IsConnected || !queue.IsOpen)
            {
                queueManager = _mqQueueManagerFactory();
                queue        = queueManager.AccessQueue(_qname, MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT);
            }
            MQPutMessageOptions pmo = new MQPutMessageOptions();

            queue.Put(value, pmo);
        }
Exemple #16
0
        /// <summary>
        /// send the message to the MQSeries's queue
        /// </summary>
        /// <param name="m">a message object to be sent</param>

        public void Send(Message m)
        {
            //create a new MQSeries message
            MQMessage message = (MQMessage)queueSession.AccessMessage();

            message.WriteString(m.Content.ToString());
            MQPutMessageOptions messageOption = (MQPutMessageOptions)queueSession.AccessPutMessageOptions();

            //send the message to the MQSeries queue
            queue.Put(message, messageOption);
        }
Exemple #17
0
        private void PutAndGetMqSeries()
        {
            Hashtable connectionProperties = init(connectionType);

            // Create a connection to the queue manager using the connection
            // properties just defined
            MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

            // Set up the options on the queue we want to open
            int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

            // Now specify the queue that we want to open,and the open options
            MQQueue system_default_local_queue =
                qMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);

            // Define an IBM MQ message, writing some text in UTF format
            MQMessage hello_world = new MQMessage();

            hello_world.WriteUTF("Hello World!");

            // Specify the message options
            MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,

            // same as MQPMO_DEFAULT

            // Put the message on the queue
            system_default_local_queue.Put(hello_world, pmo);

            // Get the message back again

            // First define an IBM MQ message buffer to receive the message
            MQMessage retrievedMessage = new MQMessage();

            retrievedMessage.MessageId = hello_world.MessageId;

            // Set the get message options
            MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults

            //same as MQGMO_DEFAULT

            // Get the message off the queue
            system_default_local_queue.Get(retrievedMessage, gmo);

            // Prove we have the message by displaying the UTF message text
            String msgText = retrievedMessage.ReadUTF();

            Console.WriteLine("The message is: {0}", msgText);

            // Close the queue
            system_default_local_queue.Close();

            // Disconnect from the queue manager
            qMgr.Disconnect();
        }
Exemple #18
0
        /// <summary>
        /// Sends reply to reply queue
        /// </summary>
        /// <param name="replyString"></param>
        /// <param name="msgId"></param>
        private void sendReply(String replyString, byte[] msgId)
        {
            MQMessage msgReply = new MQMessage();

            msgReply.WriteUTF(replyString);
            msgReply.CorrelationId = msgId;
            msgReply.Expiry        = 3000;
            MQPutMessageOptions mqPmo = new MQPutMessageOptions();

            mqPmo.Options |= MQC.MQPMO_SYNCPOINT;
            _mqReplyQueue.Put(msgReply, mqPmo);
        }
Exemple #19
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)
        {
            string location = "NBK.EAI.Adapters.MQAdapter.PushMQRequestMessage";

            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    = NBK.Common.Foundations.Utilities.ConversionUtilities
                                              .HexToBin(GenerateMQMsgId());


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

                requestMessage.WriteString(message);

                mqPutQueue.Put(requestMessage, pmo);

                string _msgId = NBK.Common.Foundations.Utilities.
                                ConversionUtilities.BinToHex(requestMessage.MessageId);

                NBK.Common.Foundations.Logging.LoggerHelper.Information
                    (location, "Sent MQ Meesage with MessageId : "
                    + _msgId);

                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));
            }
        }
Exemple #20
0
        public void PutMessage(byte[] msg)
        {
            if (!isConnected)
            {
                Init();
            }
            mqMsg = new MQMessage();
            mqMsg.Write(msg);
            mqMsg.MessageType = MQC.MQMT_DATAGRAM;
            mqPutMsgOpts      = new MQPutMessageOptions();

            mqQueue.Put(mqMsg, mqPutMsgOpts);
        }
Exemple #21
0
        /// <summary>
        /// Permite enviar un mensaje directo a la Cola del MQ
        /// Creado por: Ludwing Ottoniel Cano fuentes - 05/03/2019
        ///</summary>
        /// <param name="trama"></param>
        /// <param name="messageID"></param>
        /// <returns></returns>
        public bool PutMessages(string trama, string messageID, out string mensaje)
        {
            bool response = false;

            try
            {
                // mq properties
                properties = new Hashtable();
                properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
                properties.Add(MQC.HOST_NAME_PROPERTY, Properties.Resources.hostName);
                properties.Add(MQC.PORT_PROPERTY, Properties.Resources.port);
                properties.Add(MQC.CHANNEL_PROPERTY, Properties.Resources.channelName);

                // create connection
                queueManager = new MQQueueManager(Properties.Resources.queueManagerName, properties);
                // accessing queue
                queue = queueManager.AccessQueue(Properties.Resources.queueName_Put, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);

                // creating a message object
                message              = new MQMessage();
                message.Format       = MQC.MQFMT_STRING;
                message.CharacterSet = 437;
                message.Encoding     = 546;
                message.WriteString(trama);


                message.MessageId = Encoding.ASCII.GetBytes(messageID);

                queue.Put(message);
                mensaje  = "";
                response = true;


                // closing queue
                queue.Close();
                // disconnecting queue manager
                queueManager.Disconnect();
            }

            catch (MQException mqe)
            {
                //Console.WriteLine("");
                // Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
                //Console.WriteLine(mqe.StackTrace);
                mensaje = "No fue posible realizar la Consulta, intente nuevamente";
                //mensaje = string.Format("MQException caught: {0} - {1} - {2} - {3}", mqe.ReasonCode,mqe.Message,mqe.Reason, mqe.ToString());
                response = false;
            }
            return(response);
        }
Exemple #22
0
        private void PutMessage(string messageContent, MQPutMessageOptions putMessageOptions)
        {
            try
            {
                var message = new MQMessage();
                message.Write(Encoding.UTF8.GetBytes(messageContent));
                _queue.Put(message, putMessageOptions);
            }

            catch (MQException)
            {
                // wrap exception
                throw;
            }
        }
Exemple #23
0
        public bool SendInternal(string mess)
        {
            string messageXML = mess;
            bool   sent       = false;

            try {
                var     openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
                MQQueue queue       = queueManager.AccessQueue(queueName, openOptions);

                Console.WriteLine($"MQ Accessed Queue:  {queueName}");
                logger.Trace($"MQ Accessed Queue:  {queueName}");

                var message = new MQMessage {
                    CharacterSet = 1208 // UTF-8
                };
                message.WriteString(messageXML);
                message.Format = MQC.MQFMT_STRING;

                MQPutMessageOptions putOptions = new MQPutMessageOptions {
                    Timeout = putTimeout
                };

                Console.WriteLine($"MQ Putting Message to Queue:  {queueName} with timeout {putTimeout}");
                logger.Trace($"MQ Putting Message to Queue:  {queueName} with timeout {putTimeout}");

                queue.Put(message, putOptions);

                Console.WriteLine($"MQ Message Sent to {queueName}");
                logger.Trace($"MQ Message Sent to {queueName}");

                queue.Close();

                Console.WriteLine($"MQ Queue Closed {queueName}");
                logger.Trace($"MQ Queue Closed {queueName}");

                sent = true;
            } catch (Exception ex) {
                Console.WriteLine($"Error sending MQ Message: {ex.Message}");
                logger.Trace($"Error sending MQ Message: {ex.Message}");
                return(false);
            }
            if (!sent)
            {
                logger.Trace($"Warning: Message NOT Sent to  {queueName}");
                return(false);
            }
            return(true);
        }
        public override void Send(Message message)
        {
            var outgoing = new MQMessage();

            outgoing.Format = MQC.MQFMT_STRING;
            outgoing.WriteString(message.ToJsonString());
            if (Pattern == MessagePattern.PublishSubscribe)
            {
                _topic.Put(outgoing);
            }
            else
            {
                _queue.Put(outgoing);
            }
            _queueManager.Commit();
        }
Exemple #25
0
        public bool mtPutMessage(string varTrama)
        {
            try
            {
                if (string.IsNullOrEmpty(varTrama))
                {
                    throw new Exception(fErrorTramaInEmpty);
                }

                fQueue = fMQueueManager.AccessQueue(fQueueIN, MQC.MQOO_OUTPUT); //, fQueueManagerName, System.Guid.NewGuid().ToString(), fUser);

                fMQMsg = new MQMessage();
                fMQMsg.WriteBytes(varTrama);
                fMQMsg.Format        = MQC.MQFMT_STRING;
                fMQMsg.MessageId     = MQC.MQMI_NONE;
                fMQMsg.CorrelationId = MQC.MQCI_NONE;
                fMQMsg.CharacterSet  = 819;
                fMQMsg.Encoding      = 273;

                fPutMsgOptions = new MQPutMessageOptions();
                //fPutMsgOptions.Options = MQC.MQPMO_NEW_CORREL_ID;

                //coloca el mensaje en la trama
                fQueue.Put(fMQMsg, fPutMsgOptions);
                //fCorrelationId = fMQMsg.CorrelationId;
                fCorrelationId = fMQMsg.MessageId;

                return(true);
            }
            catch (Exception ex)
            {
                if (ex is MQException)
                {
                    throw new Exception(((MQException)ex).Message + " MQ Error Code: " + ((MQException)ex).ReasonCode.ToString());
                }
                else
                {
                    throw (ex);
                }
            }
            finally
            {
                fQueue?.Close();
            }
        }
Exemple #26
0
        void SendMessage(string msg)
        {
            try
            {
                // mq properties
                Hashtable properties = new Hashtable();
                properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
                properties.Add(MQC.HOST_NAME_PROPERTY, HostName);
                properties.Add(MQC.PORT_PROPERTY, Port);
                properties.Add(MQC.CHANNEL_PROPERTY, ChannelName);

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

                // accessing queue
                Console.Write("Accessing queue " + QueueName + ".. ");
                MQQueue queue = queueManager.AccessQueue(QueueName, MQC.MQOO_OUTPUT);
                Console.WriteLine("done");

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

                // send the message
                queue.Put(message);

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

                // disconnecting queue manager
                Console.Write("Disconnecting queue manager.. ");
                queueManager.Disconnect();
                Console.WriteLine("done");
            }
            catch (MQException mqe)
            {
                Console.WriteLine("");
                Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
                Console.WriteLine(mqe.StackTrace);
            }
        }
Exemple #27
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));
            }
        }
Exemple #28
0
        /// <summary>
        /// Helper method to write a message to an MQ Series queue
        /// </summary>
        ///
        /// <param name="queueManagerName">The name of the MQ Series queue manager</param>
        /// <param name="queueName">The name of the MQ Series queue to read from</param>
        /// <param name="message">The MQ Series queue</param>
        /// <param name="correlId">The correlation ID to be set on the new message</param>
        /// <param name="context">The BizUnit context object which holds state and is passed between test steps</param>
        static public void WriteMessage(string queueManagerName, string queueName, string message, byte[] correlId, Context context)
        {
            MQQueueManager      queueManager = null;
            MQQueue             sendQueue    = null;
            MQMessage           mqMessage;
            MQPutMessageOptions mqPutMsgOpts;

            try
            {
                context.LogInfo("Opening queue manager: \"{0}\"", queueManagerName);
                queueManager = new MQQueueManager(queueManagerName);

                context.LogInfo("Opening queue: '{0}'.", queueName);
                sendQueue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);

                mqMessage = new MQMessage();
                byte[] data = ConvertToBytes(message);
                mqMessage.Write(data);
                mqMessage.Format = MQC.MQFMT_STRING;
                mqPutMsgOpts     = new MQPutMessageOptions();

                context.LogInfo("Writing {0} byte message to queue '{1}'.", data.Length, queueName);

                if (correlId != null)
                {
                    mqMessage.CorrelationId = correlId;
                }

                sendQueue.Put(mqMessage, mqPutMsgOpts);
            }
            finally
            {
                if (sendQueue != null)
                {
                    sendQueue.Close();
                }

                if (queueManager != null)
                {
                    queueManager.Close();
                }
            }
        }
        public void QueuePutGet_Ok()
        {
            var message = "PutInQueue";

            using (var broker = MQQueueManager.Connect(QueueManagerName, 0, Channel, ConnectionInfo))
                using (var q = new MQQueue(broker, QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING))
                {
                    var outgoing = new MQMessage()
                    {
                        CharacterSet = MQC.CODESET_UTF,
                        Encoding     = MQC.MQENC_NORMAL
                    };
                    outgoing.WriteString(message);
                    q.Put(outgoing, new MQPutMessageOptions());

                    var incoming = new MQMessage();
                    q.Get(incoming, new MQGetMessageOptions());
                    Assert.AreEqual(message, incoming.ReadAll());
                }
        }
Exemple #30
0
        public string WriteMsg(string strInputMsg)
        {
            string strReturn = "";

            try
            {
                queue = queueManager.AccessQueue(QueueName,
                                                 MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);

                message      = strInputMsg;
                queueMessage = new MQMessage();
                queueMessage.WriteBytes(strInputMsg);
                queueMessage.ReplyToQueueName        = "MBK.SESION3.SALIDA";
                queueMessage.OriginalLength          = 120;
                queueMessage.ReplyToQueueManagerName = "IB9QMGR";
                queueMessage.DataOffset = 328;
                queueMessage.Format     = MQC.MQFMT_STRING;
                queuePutMessageOptions  = new MQPutMessageOptions();



                try
                {
                    queue.Put(queueMessage, queuePutMessageOptions);
                    strReturn = "Message sent to the queue successfully";
                }
                catch (MQException e)
                {
                    strReturn = "Exception: " + "error al colocar(put) el mensaje en la cola " + QueueName + ". " + e.ToString();
                }
            }
            catch (MQException MQexp)
            {
                strReturn = "Exception: " + MQexp.Message;
            }
            catch (Exception exp)
            {
                strReturn = "Exception: " + exp.Message;
            }
            return(strReturn);
        }
Exemple #31
0
        public string WriteMsg(string strInputMsg)
        {
            string strReturn = "";
            try
            {
                queue = queueManager.AccessQueue(QueueName,
                    MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);

                message = strInputMsg;
                queueMessage = new MQMessage();
                queueMessage.WriteBytes(strInputMsg);
                queueMessage.ReplyToQueueName = "MBK.SESION3.SALIDA";
                queueMessage.OriginalLength = 120;
                queueMessage.ReplyToQueueManagerName = "IB9QMGR";
                queueMessage.DataOffset = 328;
                queueMessage.Format = MQC.MQFMT_STRING;
                queuePutMessageOptions = new MQPutMessageOptions();



                try
                {
                    queue.Put(queueMessage, queuePutMessageOptions);
                    strReturn = "Message sent to the queue successfully";
                }
                catch (MQException e)
                {
                    strReturn = "Exception: " + "error al colocar(put) el mensaje en la cola " + QueueName + ". " + e.ToString();
                }

            }
            catch (MQException MQexp)
            {
                strReturn = "Exception: " + MQexp.Message;
            }
            catch (Exception exp)
            {
                strReturn = "Exception: " + exp.Message;
            }
            return strReturn;
        }
Exemple #32
0
        /// <summary>
        /// Write Message to Local Queue
        /// </summary>
        /// <param name="strInputMsg">Text Message</param>
        /// <param name="strqueueName">Queue Name</param>
        /// <returns></returns>
        public MQMessageStatus WriteLocalQMsg(string strInputMsg, string strQueueName)
        {
            MQMessageStatus messageStatus = new MQMessageStatus();
            string strReturn = string.Empty;
            SendQueueName = strQueueName;
            try
            {
                queue = queueManager.AccessQueue(SendQueueName,
                  MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                message = strInputMsg;
                queueMessage = new MQMessage();
                queueMessage.WriteString(message);
                queueMessage.Format = MQC.MQFMT_STRING;
                queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);
                strReturn = "Message sent to the queue successfully";

                messageStatus.Message = strReturn;
                messageStatus.Status = true;
            }
            catch (MQException MQexp)
            {
                strReturn = "Exception: " + MQexp.Message;
                messageStatus.Message = strReturn;
                messageStatus.Status = false;
            }
            catch (Exception exp)
            {
                strReturn = "Exception: " + exp.Message;
                messageStatus.Message = strReturn;
                messageStatus.Status = false;
            }
            return messageStatus;
        }