public Task MessageReceived(Message message, IQueuedMessageContext context,
                             CancellationToken cancellationToken = new CancellationToken())
 {
     if (Interlocked.Increment(ref _count) >= _target)
     {
         _taskCompletionSource.TrySetResult(message);
     }
     return(Task.FromResult(0));
 }
Пример #2
0
        /// <inheritdoc />
        public async Task MessageReceived(Message message, IQueuedMessageContext context,
                                          CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageContext = new BusMessageContext(_bus, context.Headers, context.Principal);
            await _messageHandler.HandleMessage(_messageHandlers, message, messageContext, cancellationToken);

            if (messageContext.MessageAcknowledged)
            {
                await context.Acknowledge();
            }
        }
Пример #3
0
        public async Task MessageReceived(Message message, IQueuedMessageContext context,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageContext = new BusMessageContext(_bus, context.Headers, context.SenderPrincipal);
            await MessageHandler.HandleMessage(_messageNamingService, _serializationService, _messageHandlers,
                message, messageContext, cancellationToken);

            if (messageContext.MessageAcknowledged)
            {
                await context.Acknowledge();
            }
        }
Пример #4
0
 public async Task MessageReceived(Message message, IQueuedMessageContext context,
     CancellationToken cancellationToken = new CancellationToken())
 {
     IEndpoint endpoint;
     IEndpointCredentials credentials = null;
     if (_endpoints.TryGetEndpointByAddress(message.Headers.Destination, out endpoint))
     {
         credentials = endpoint.Credentials;
     }
     cancellationToken.ThrowIfCancellationRequested();
     await TransportMessage(message, credentials, cancellationToken);
     await context.Acknowledge();
 }
 public Task MessageReceived(Message message, IQueuedMessageContext context,
                             CancellationToken cancellationToken = new CancellationToken())
 {
     Message = message;
     Context = context;
     try
     {
         _callback(message, context);
         return(Task.FromResult(0));
     }
     finally
     {
         _taskCompletionSource.TrySetResult(message);
     }
 }
Пример #6
0
        /// <inheritdoc />
        /// <summary>
        /// Handles a message that is received off of a queue
        /// </summary>
        /// <param name="message">The message that was received</param>
        /// <param name="context">The context in which the message was dequeued</param>
        /// <param name="cancellationToken">A cancellation token provided by the
        /// queue that can be used to cancel message processing</param>
        /// <returns>Returns a task that completes when the message is processed</returns>
        async Task IQueueListener.MessageReceived(Message message, IQueuedMessageContext context,
                                                  CancellationToken cancellationToken)
        {
            IEndpointCredentials credentials = null;

            if (_endpoints.TryGetEndpointByAddress(message.Headers.Destination, out IEndpoint endpoint))
            {
                credentials = endpoint.Credentials;
            }
            cancellationToken.ThrowIfCancellationRequested();
            Thread.CurrentPrincipal = context.Principal;
            await TransportMessage(message, credentials, cancellationToken);

            await context.Acknowledge();
        }
Пример #7
0
        public async Task MessageReceived(Message message, IQueuedMessageContext context,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (message.Headers.Expires < DateTime.UtcNow)
            {
                Log.WarnFormat("Discarding expired \"{0}\" message (ID {1}, expired {2})",
                    message.Headers.MessageName, message.Headers.MessageId, message.Headers.Expires);

                await context.Acknowledge();
                return;
            }

            var credentials = _credentialsFactory(message.Headers.Destination);

            await _transportService.SendMessage(message, credentials, cancellationToken);
            await context.Acknowledge();

            if (_messageJournalingService != null)
            {
                await _messageJournalingService.MessageSent(message, cancellationToken);
            }
        }
Пример #8
0
 public Task MessageReceived(Message message, IQueuedMessageContext context,
                             CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.FromResult(false));
 }
 public Task MessageReceived(Message message, IQueuedMessageContext context,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return Task.FromResult(false);
 }
Пример #10
0
        /// <inheritdoc />
        async Task IQueueListener.MessageReceived(Message message, IQueuedMessageContext context, CancellationToken cancellationToken)
        {
            await _transportService.ReceiveMessage(message, context.Principal, cancellationToken);

            await context.Acknowledge();
        }