Exemple #1
0
        /// <summary>
        /// Uses a <see cref="QueueCursor"/> to look for messages with a matching <paramref name="correlationId"/>.
        /// Returns the matching message or NULL if no matching message can be found with the allowed <paramref name="timeout"/>.
        /// </summary>
        public static Message ReadByCorrelationId(this QueueReader queue, MessageId correlationId, Properties properties = Properties.All, TimeSpan?timeout = null, QueueTransaction transaction = null)
        {
            timeout = timeout ?? QueueReader.Infinite;
            var start = DateTime.UtcNow;

            using (var cur = new QueueCursor(queue))
            {
                var msg = cur.Peek(Properties.CorrelationId | Properties.LookupId, timeout);
                for (;;)
                {
                    if (msg == null)
                    {
                        return(null);
                    }

                    if (msg.CorrelationId == correlationId)
                    {
                        return(queue.Lookup(properties, msg.LookupId, LookupAction.ReceiveCurrent, TimeSpan.Zero, transaction));
                    }

                    var elapsed   = DateTime.UtcNow - start;
                    var remaining = timeout - elapsed;
                    if (remaining <= TimeSpan.Zero)
                    {
                        return(null);
                    }

                    msg = cur.PeekNext(Properties.CorrelationId | Properties.LookupId, remaining);
                }
            }
        }
 /// <summary>Peeks at all the messages currently in the queue using a <see cref="QueueCursor"/></summary>
 public IEnumerator <Message> GetEnumerator()
 {
     using (var c = new QueueCursor(this))
     {
         for (var msg = c.Peek(timeout:TimeSpan.Zero); msg != null; msg = c.PeekNext(timeout: TimeSpan.Zero))
         {
             yield return(msg);
         }
     }
 }