Ejemplo n.º 1
0
 /// <summary>
 /// Will pass an incoming message to the <see cref="Receiver"/> for processing.
 /// </summary>
 /// <param name="message"></param>
 /// <param name="cancellationToken"></param>
 protected async Task ReceiveMessageAsync(Message message, CancellationToken cancellationToken)
 {
     try
     {
         ProcessingMessage.Wait(cancellationToken);
         var combined = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, StopProcessingMessageToken).Token;
         await Receiver.ReceiveMessageAsync(message, combined);
     }
     finally
     {
         ProcessingMessage.Release();
     }
 }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _stopProcessingMessageTokenSource.Cancel();
            _stopProcessingMessageTokenSource.Dispose();

            ProcessingMessage.Release(MaxConcurrentCalls ?? 1);
            ProcessingMessage.Dispose();
        }
Ejemplo n.º 3
0
        protected override void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (MaxConcurrentCalls.HasValue)
            {
                ProcessingMessage.Release(MaxConcurrentCalls.Value);
            }
            else
            {
                ProcessingMessage.Release();
            }

            ProcessingMessage.Dispose();

            base.Dispose(disposing);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Will pass an incoming message to the <see cref="Receiver"/> for processing.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="cancellationToken"></param>
        protected async Task ReceiveMessageAsync(Message message, CancellationToken cancellationToken)
        {
            try
            {
                if (IsClosing)
                {
                    // We want the thread to sleep and not return immediately.
                    // Returning immediately could increment the message fail count and send it to dead letter.
                    Thread.Sleep(CloseTimeout);
                    return;
                }

                ProcessingMessage.Wait(cancellationToken);
                var combined = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, StopProcessingMessageToken).Token;
                await Receiver.ReceiveMessageAsync(message, combined);
            }
            finally
            {
                ProcessingMessage.Release();
            }
        }