/// <inheritdoc /> public async Task <PullResult> PullAsync(CancellationToken cancellationToken = default) { using var cts = cancellationToken.WithTimeout(options.Timeout); var basicGetResult = await channel.InvokeChannelActionAsync( x => x.BasicGet(queue.Name, options.AutoAck), cts.Token ).ConfigureAwait(false); if (basicGetResult == null) { return(PullResult.NotAvailable); } var messagesCount = basicGetResult.MessageCount; var message = new ConsumedMessage( new MessageReceivedInfo( "", basicGetResult.DeliveryTag, basicGetResult.Redelivered, basicGetResult.Exchange, basicGetResult.RoutingKey, queue.Name ), new MessageProperties(basicGetResult.BasicProperties), basicGetResult.Body.ToArray() ); var interceptedMessage = interceptor.OnConsume(message); return(PullResult.Available( messagesCount, interceptedMessage.ReceivedInfo, interceptedMessage.Properties, interceptedMessage.Body )); }
public static void InvokeChannelAction( this IPersistentChannel source, Action <IModel> channelAction, CancellationToken cancellationToken = default ) { source.InvokeChannelActionAsync(channelAction, cancellationToken) .GetAwaiter() .GetResult(); }