Example #1
0
 /// <summary>
 /// Deletes the specified message from the queue.
 /// </summary>
 /// <param name="poppedMessage">Message to delete from the queue</param>
 public void DeleteMessage(IPoppedMessage poppedMessage)
 {
     CheckIfDeleted();
     lock (_locker)
     {
         var message = _messages.Single(m => m.Id == poppedMessage.Id &&
                                             m.PopReceipt == poppedMessage.PopReceipt &&
                                             m.NextVisibleTime >= EnvironmentInfo.GetCurrentDateTimeUtc());
         if (message != null) _messages.Remove(message);
     }
 }
 /// <summary>
 /// Deletes the specified message from the queue.
 /// </summary>
 /// <param name="poppedMessage">Message to delete from the queue</param>
 public void DeleteMessage(IPoppedMessage poppedMessage)
 {
     CheckIfDeleted();
     lock (_locker)
     {
         var message = _messages.Single(m => m.Id == poppedMessage.Id &&
                                        m.PopReceipt == poppedMessage.PopReceipt &&
                                        m.NextVisibleTime >= EnvironmentInfo.GetCurrentDateTimeUtc());
         if (message != null)
         {
             _messages.Remove(message);
         }
     }
 }
        /// <summary>
        /// Processes a single message
        /// </summary>
        /// <param name="message">Message to process</param>
        /// <returns></returns>
        private bool ProcessMessage(IPoppedMessage message)
        {
            if (ShouldStopTaskProcessing)
            {
                return(true);
            }
            var task = new TTask();

            // --- Set input arguments
            task.Argument = task.ArgumentConverter.ConvertToArgument(message.MessageText);

            // --- Prepare task to run
            var cancel = false;

            OnTaskProcessing(task, ref cancel);

            var stopwatch = new Stopwatch();

            try
            {
                // --- Setup with graceful cancellation
                if (ShouldStopTaskProcessing)
                {
                    return(true);
                }
                task.Setup(Context);

                // --- Run with graceful cancellation
                CancellationToken.ThrowIfCancellationRequested();
                task.Run();
                OnTaskProcessed(task);
                NumTasksPmc.Increment();
                NumTasksPerSecondPmc.Increment();

                // --- At this point the message should be removed from the queue
                _requestQueue.DeleteMessage(message);
                return(false);
            }
            catch
            {
                NumFailuresPmc.Increment();
                NumFailuresPerSecondPmc.Increment();
                throw;
            }
            finally
            {
                LastProcessTimePmc.RawValue = (int)stopwatch.ElapsedMilliseconds;
                task.Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// This method will delete the popped message from the queue. Does nothing when message does not exist
        /// </summary>
        /// <param name="poppedMessage">The nessage you want to delete</param>
        public void DeleteMessage(IPoppedMessage poppedMessage)
        {
            using (var conn = SqlHelper.CreateSqlConnection(Provider.NameOrConnectionString))
            {
                conn.Open();

                using (var command = new SqlCommand())
                {
                    command.Connection = conn;
                    command.Parameters.Add("@messageid", SqlDbType.UniqueIdentifier).Value =
                        Guid.Parse(poppedMessage.Id);
                    command.Parameters.Add("@popreceipt", SqlDbType.UniqueIdentifier).Value =
                        Guid.Parse(poppedMessage.PopReceipt);
                    command.CommandText = GetDeleteMessagesSql();
                    var rows = command.ExecuteNonQuery();
                    if (rows == 0)
                    {
                        throw new InvalidOperationException("No message has been deleted.");
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// This method will delete the popped message from the queue. Does nothing when message does not exist
        /// </summary>
        /// <param name="poppedMessage">The nessage you want to delete</param>
        public void DeleteMessage(IPoppedMessage poppedMessage)
        {
            using (var conn = SqlHelper.CreateSqlConnection(Provider.NameOrConnectionString))
            {
                conn.Open();

                using (var command = new SqlCommand())
                {
                    command.Connection = conn;
                    command.Parameters.Add("@messageid", SqlDbType.UniqueIdentifier).Value =
                        Guid.Parse(poppedMessage.Id);
                    command.Parameters.Add("@popreceipt", SqlDbType.UniqueIdentifier).Value =
                        Guid.Parse(poppedMessage.PopReceipt);
                    command.CommandText = GetDeleteMessagesSql();
                    var rows = command.ExecuteNonQuery();
                    if (rows == 0)
                    {
                        throw new InvalidOperationException("No message has been deleted.");
                    }
                }
            }
        }