public void PutReportMessage(MQMessage message, MQPutMessageOptions putMessageOptions) { uint method = 0x22d; this.TrEntry(method, new object[] { message, putMessageOptions }); int compCode = 0; int reason = 0; try { if (message == null) { base.throwNewMQException(2, 0x7ea); } if (putMessageOptions == null) { base.throwNewMQException(2, 0x87d); } MQMessage newMsg = new MQMessage(); if ((putMessageOptions.Options & 0x800000) != 0) { newMsg = this.CopyMDFromOldMsgIntoReportMsg(message, newMsg, putMessageOptions.Options); putMessageOptions.Options &= -8388609; } IEnumerator propertyNames = message.GetPropertyNames("%"); MQPropertyDescriptor pd = new MQPropertyDescriptor(); while (propertyNames.MoveNext()) { string name = propertyNames.Current.ToString(); object objectProperty = message.GetObjectProperty(name, pd); if (this.ValidToCopy(pd.CopyOptions, 0x10)) { newMsg.SetObjectProperty(name, pd, objectProperty); } } base.Put(newMsg, putMessageOptions); } catch (MQException exception) { compCode = exception.CompCode; reason = exception.Reason; throw exception; } finally { base.unsafe_compCode = compCode; base.unsafe_reason = reason; base.TrExit(method); } }
public MqMessageGeneric GetNextMessage() { MqMessageGeneric res = null; String qname = this.queueName; if (String.IsNullOrWhiteSpace(qname)) { throw new ArgumentNullException("Не определено имя очереди"); } var getMessageOptions = new MQGetMessageOptions(); getMessageOptions.Options = MQC.MQGMO_WAIT + MQC.MQGMO_SYNCPOINT; getMessageOptions.WaitInterval = 100; // 1 seconds wait try { if (mqManager == null) { mqManager = createManager(); } message = new MQMessage(); using (var queue = mqManager.AccessQueue(queueName, MQC.MQOO_INQUIRE)) if (queue.CurrentDepth == 0) { return(res); } using (var q = mqManager.AccessQueue(qname, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING)) q.Get(message, getMessageOptions); res = new MqMessageGeneric(); res.Body = Encoding.UTF8.GetString(message.ReadBytes(message.MessageLength)); res.MessageID = message.MessageId; res.PutDateTime = message.PutDateTime; var inames = message.GetPropertyNames("%"); if (inames != null) { while (inames.MoveNext()) { String name = inames.Current.ToString(); if (name.ToLower().Contains("jms") || name.ToLower().Contains("mcd")) { continue; } res.AddedProperties.Add(name, message.GetStringProperty(name)); } } } catch (MQException mqex) { RollbackGet(); message = null; if (mqex.ReasonCode == 2033 && mqex.CompCode == 2) // В очереди нет сообщений { return(null); } throw new InvalidOperationException(String.Format("MQ {0}", mqex.Message)); } catch { RollbackGet(); throw; } return(res); }