public override bool Execute() { Log.LogMessage("Starting Websphere MQ Server " + QueueManagerName); IBM.WMQ.MQQueueManager queueManager = new IBM.WMQ.MQQueueManager(QueueManagerName); Log.LogMessage("Opening queue " + InputQueueName); IBM.WMQ.MQQueue queue = queueManager.AccessQueue(InputQueueName, IBM.WMQ.MQC.MQOO_INPUT_SHARED); int count = 0; while (true) { try { IBM.WMQ.MQMessage msg = new IBM.WMQ.MQMessage(); queue.Get(msg); MemoryStream ms = new MemoryStream(); MemoryStream respStream = new MemoryStream(); MQUtil.MQMessageToStream(msg, ms); msg.ClearMessage(); StreamUtil.ProcessClientBigRequest(ConnString, ms, respStream, false, null); MQUtil.StreamToMQMessage(respStream, msg); queueManager.Put(OutputQueueName, msg); queueManager.Commit(); msg.ClearMessage(); count++; Log.LogMessage("Processed " + count.ToString()); } catch (IBM.WMQ.MQException ex) { if (ex.ReasonCode != IBM.WMQ.MQC.MQRC_NO_MSG_AVAILABLE) throw; else Thread.Sleep(50); } } }
private void ProcessMQQueue() { bool keepListening = true; while (keepListening) { try { IBM.WMQ.MQMessage msg = new IBM.WMQ.MQMessage(); inputQueue.Get(msg); queueManager.Commit(); messageCount--; MemoryStream ms = new MemoryStream(); MQUtil.MQMessageToStream(msg, ms); msg.ClearMessage(); Log.LogMessage("Waiting for more " + messageCount.ToString()); StreamUtil.ImportarStream(ConnString, ms); if (messageCount <= 0) { keepListening = false; finished = true; } } catch (IBM.WMQ.MQException exception) { if (exception.ReasonCode != IBM.WMQ.MQC.MQRC_NO_MSG_AVAILABLE) throw; else Thread.Sleep(100); } } }