public void Dispose() { if (innerEnumerator != null) { innerEnumerator.Close(); innerEnumerator = null; } }
public void Ids() { Message once; Message twice; using (MessageEnumerator enumerator = _queue.GetMessageEnumerator2()) { if (enumerator.MoveNext()) { once = enumerator.Current; enumerator.MoveNext(); twice = enumerator.RemoveCurrent(); Assert.AreNotSame(once.Id, twice.Id); var b = twice.BodyType; } enumerator.Close(); } }
//[Test] // Not supported with AMQP public void RemoveMessageWithTx() { MessageQueue q = MQUtil.GetQueue(qName); q.Formatter = new BinaryMessageFormatter(); q.Send("foo1"); q.Send("foo2"); MessageEnumerator me1 = q.GetMessageEnumerator(); MessageQueueTransaction tx = new MessageQueueTransaction(); me1.MoveNext(); Message m1 = me1.Current; me1.RemoveCurrent(tx); tx.Commit(); me1.Close(); MessageEnumerator me2 = q.GetMessageEnumerator(); Assert.IsTrue(me1.MoveNext()); me2.RemoveCurrent(); Assert.IsFalse(me2.MoveNext()); }
public override IEnumerable <QueueItem> GetProcessedMessages(QueueType type, DateTime since, IEnumerable <QueueItem> currentItems) { List <QueueItem> r = new List <QueueItem>(); var queues = GetQueueListByType(type); if (queues.Count() == 0) { return(EMPTY_LIST); } foreach (var q in queues) { string qName = q.GetDisplayName(); if (IsIgnoredQueue(qName) || !q.CanReadJournalQueue) { continue; } SetupMessageReadPropertyFilters(q.Journal, type); try { List <Message> messages = new List <Message>(); // Enumete from the earliest item MessageEnumerator msgs = q.Journal.GetMessageEnumerator2(); try { while (msgs.MoveNext()) { Message msg = msgs.Current; if (msg.ArrivedTime >= since) { messages.Add(msg); } } } finally { msgs.Close(); } foreach (var msg in messages) { QueueItem itm = currentItems.FirstOrDefault(i => i.Id == msg.Id); if (itm == null) { itm = CreateQueueItem(q.Queue, msg); itm.Processed = true; if (!PrepareQueueItemForAdd(itm)) { itm = null; } } if (itm != null) { r.Insert(0, itm); } } } catch (Exception e) { OnError("Error occured when getting processed messages from queue \"" + qName + "\", " + e.Message, e, false); } } return(r); }