Exemplo n.º 1
0
 /// <summary>
 /// Gets messages from the queue.
 /// </summary>
 /// <param name="numberOfMessages">Number of messages to retrieve from the queue</param>
 /// <param name="visibilityTimeoutInSeconds">
 /// Timeot while messages are invisible for other GetMessages requests</param>
 /// <returns>The collection of messages obtained from the queue.</returns>
 public IEnumerable <IPoppedMessage> GetMessages(int numberOfMessages, int visibilityTimeoutInSeconds)
 {
     CheckIfDeleted();
     lock (_locker)
     {
         var now    = EnvironmentInfo.GetCurrentDateTimeUtc();
         var result = (from m in _messages
                       where m.NextVisibleTime <now && m.ExpirationTime> now
                       orderby m.InsertionTime descending
                       select m).Take(numberOfMessages).ToList();
         var copyResult = new List <MemoryPoppedMessage>();
         foreach (var message in result)
         {
             message.DequeueCount++;
             message.PopReceipt      = Guid.NewGuid().ToString();
             message.NextVisibleTime = now.AddSeconds(visibilityTimeoutInSeconds);
             var copyAdd = new MemoryPoppedMessage
             {
                 DequeueCount    = message.DequeueCount,
                 ExpirationTime  = message.ExpirationTime,
                 Id              = message.Id,
                 InsertionTime   = message.InsertionTime,
                 MessageText     = message.MessageText,
                 PopReceipt      = message.PopReceipt,
                 NextVisibleTime = message.NextVisibleTime
             };
             copyResult.Add(copyAdd);
         }
         return(copyResult);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets messages from the queue.
 /// </summary>
 /// <param name="numberOfMessages">Number of messages to retrieve from the queue</param>
 /// <param name="visibilityTimeoutInSeconds">
 /// Timeot while messages are invisible for other GetMessages requests</param>
 /// <returns>The collection of messages obtained from the queue.</returns>
 public IEnumerable<IPoppedMessage> GetMessages(int numberOfMessages, int visibilityTimeoutInSeconds)
 {
     CheckIfDeleted();
     lock (_locker)
     {
         var now = EnvironmentInfo.GetCurrentDateTimeUtc();
         var result = (from m in _messages
                       where m.NextVisibleTime < now && m.ExpirationTime > now
                       orderby m.InsertionTime descending
                       select m).Take(numberOfMessages).ToList();
         var copyResult = new List<MemoryPoppedMessage>();
         foreach (var message in result)
         {
             message.DequeueCount++;
             message.PopReceipt = Guid.NewGuid().ToString();
             message.NextVisibleTime = now.AddSeconds(visibilityTimeoutInSeconds);
             var copyAdd = new MemoryPoppedMessage
             {
                 DequeueCount = message.DequeueCount,
                 ExpirationTime = message.ExpirationTime,
                 Id = message.Id,
                 InsertionTime = message.InsertionTime,
                 MessageText = message.MessageText,
                 PopReceipt = message.PopReceipt,
                 NextVisibleTime = message.NextVisibleTime
             };
             copyResult.Add(copyAdd);
         }
         return copyResult;
     }
 }