public RequeuingWithDelayExceptionHandler(
            IUntypedQueuesFactory <RabbitQueueCreationOptions, QueueBase <RabbitMessageDescription> > rabbitQueuesFactory,
            ILogger <RequeuingWithDelayExceptionHandler> logger,
            string parentQueueName,
            TimeSpan messageDelay)
            : base(logger, ExceptionHandlingPolicy.Requeue)
        {
            if (rabbitQueuesFactory == null)
            {
                throw new ArgumentNullException(nameof(rabbitQueuesFactory));
            }

            _pendingMessagesQueue = rabbitQueuesFactory.Create(
                new RabbitQueueCreationOptions
            {
                QueueName = $"{parentQueueName}_PendingMessages_{messageDelay}",
                ExceptionHandlingPolicy = ExceptionHandlingPolicy.None,
                RetriesCount            = 0,
                RetryInitialTimeout     = TimeSpan.Zero,
                AdditionalArguments
                    = new Dictionary <string, object>
                    {
                        { "x-dead-letter-exchange", "" },
                        { "x-dead-letter-routing-key", parentQueueName },
                        { "x-message-ttl", (long)messageDelay.TotalMilliseconds },
                        { "x-expires", (long)messageDelay.TotalMilliseconds * 2 }
                    }
            }
                );
        }
Esempio n. 2
0
        public void TestDequeue(QueueBase <string> queue)
        {
            var threads = Enumerable
                          .Range(0, _threadCount)
                          .Select(
                n => new Thread(
                    () =>
            {
                var left = _iterations;
                while (left > 0)
                {
                    string res;
                    if (queue.TryDequeue(out res))
                    {
                        left--;
                    }
                }
            }))
                          .ToArray();

            foreach (var thread in threads)
            {
                thread.Start();
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
 protected override async Task HandleExceptionAsync(
     QueueBase <TMessageDescription> queue,
     TMessageDescription messageDescription,
     Exception exception,
     CancellationToken cancellationToken)
 {
     await queue.RejectMessageAsync(messageDescription, cancellationToken);
 }
Esempio n. 4
0
        public static void Enqueue(TopicMessage msg)
        {
            QueueBase queue = new QueueBase();

            queue = _dic.GetOrAdd(msg.Topic, queue);
            queue.Enqueue(msg.Content);
            Interlocked.Increment(ref _in);
        }
        protected override async Task HandleExceptionAsync(
            QueueBase <RabbitMessageDescription> queue,
            RabbitMessageDescription messageDescription,
            Exception exception,
            CancellationToken cancellationToken)
        {
            await queue.AcknowledgeMessageAsync(messageDescription, cancellationToken);

            await _pendingMessagesQueue.SendMessageAsync(messageDescription, cancellationToken);
        }
Esempio n. 6
0
 public async Task HandleAsync(
     QueueBase <TMessageDescription> queue,
     TMessageDescription messageDescription,
     Exception exception,
     CancellationToken cancellationToken)
 {
     try
     {
         await HandleExceptionAsync(queue, messageDescription, exception, cancellationToken);
     }
     catch (Exception e)
     {
         Logger.LogError(e, "Error during has occurred during handling previous exception");
     }
 }
        protected override async Task HandleExceptionAsync(
            QueueBase <TMessageDescription> queue,
            TMessageDescription messageDescription,
            Exception exception,
            CancellationToken cancellationToken)
        {
            await queue.AcknowledgeMessageAsync(messageDescription, cancellationToken);

            await queue.ErrorsQueue.SendMessageAsync(
                new ExceptionDescription
            {
                ExceptionMessage = exception.Message,
                MessageId        = messageDescription.Id,
                MessageContent   = messageDescription.Content
            },
                cancellationToken
                );
        }
Esempio n. 8
0
        protected void HandleException(Exception exception, QueueResult queueResult, QueueBase queueBase)
        {
            ExceptionCode?code = null;

            if (exception is BusinessException)
            {
                code = (exception as BusinessException).Code;
                queueResult.ExceptionCode = code;

                //Concatenate additionalData
                foreach (var item in (exception as BusinessException).AdditionalData)
                {
                    queueResult.AdditionalData.Add(item.Key, item.Value);
                }
            }
            else
            {
                queueResult.ExceptionCode = ExceptionCode.Error;
            }
            queueResult.Status = Status.Fail;

            #region Helper
            int?intCode = null;
            if (code.HasValue)
            {
                intCode = (int)code.Value;
            }

            string tenantId = null;
            string userId   = null;

            if (queueBase != null)
            {
                tenantId = queueBase.TenantId.ToString();
                userId   = queueBase.UserPerformingAction.ToString();
            }
            #endregion

            this.logger.LogCustomError($"Failed to execute action", exception, intCode, tenantId, userId);
        }
Esempio n. 9
0
        public static TopicMessage Dequque(string topic)
        {
            string msg = null;

            QueueBase queue = null;

            if (_dic.TryGetValue(topic, out queue))
            {
                msg = queue.Dequeue();

                if (!string.IsNullOrEmpty(msg))
                {
                    Interlocked.Increment(ref _out);

                    return(new TopicMessage()
                    {
                        Topic = topic, Content = msg
                    });
                }
            }
            return(null);
        }
Esempio n. 10
0
        public void TestEnqueueDequeue(QueueBase <string> queue, int threadCount)
        {
            var threads = Enumerable
                          .Range(0, threadCount)
                          .Select(
                n => new Thread(
                    () =>
            {
                for (var i = 0; i < _iterations; i++)
                {
                    queue.Enqueue(i.ToString());
                }
            }))
                          .Concat(new[] { new Thread(() =>
                {
                    var left = _iterations;
                    while (left > 0)
                    {
                        string res;
                        if (queue.TryDequeue(out res))
                        {
                            left--;
                        }
                    }
                }) })
                          .ToArray();

            foreach (var thread in threads)
            {
                thread.Start();
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
Esempio n. 11
0
        public void TestEnqueue(QueueBase <string> queue, int threadCount)
        {
            var threads = Enumerable
                          .Range(0, threadCount)
                          .Select(
                n => new Thread(
                    () =>
            {
                for (var i = 0; i < _iterations; i++)
                {
                    queue.Enqueue(i.ToString());
                }
            }))
                          .ToArray();

            foreach (var thread in threads)
            {
                thread.Start();
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
Esempio n. 12
0
 public QueueRunner(QueueBase queue, Operation[] enqueue_ops)
 {
 }
Esempio n. 13
0
 protected abstract Task HandleExceptionAsync(
     QueueBase <TMessageDescription> queue,
     TMessageDescription messageDescription,
     Exception exception,
     CancellationToken cancellationToken);