private async Task OnMessageReceivedAsync( Func <IMessage, CancellationToken, Task> messageHandler, MessageHandlerOptions messageHandlerOptions, BasicDeliverEventArgs eventArgs) { var cancellationToken = CancellationToken.None; var message = new RabbitMQMessage( eventArgs.Body, eventArgs.DeliveryTag, eventArgs.BasicProperties); try { await messageHandler(message, cancellationToken); if (messageHandlerOptions.AutoComplete) { await CompleteAsync(message, cancellationToken); } } catch (Exception ex) { try { var exceptionHandler = messageHandlerOptions?.ExceptionReceivedHandler; if (exceptionHandler != null) { var context = new MessageHandlerExceptionContext(ex); await exceptionHandler(context); } } catch { } await AbandonAsync(message, cancellationToken); } }
public override Task <IMessage> DequeueAsync( CancellationToken cancellationToken = default(CancellationToken)) { BasicGetResult result; lock (_channel) { result = _channel.BasicGet(_queueName, autoAck: false); } if (result == null) { return(Task.FromResult <IMessage>(null)); } var message = new RabbitMQMessage( result.Body, result.DeliveryTag, result.BasicProperties); return(Task.FromResult <IMessage>(message)); }