/// <summary> /// Fetches the next batch of active messages without changing the state of the receiver or the message source. /// </summary> /// <param name="sequenceNumber">The sequence number from where to peek the message.</param> /// <param name="maxMessages">The maximum number of messages that will be fetched.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// <returns>An <see cref="IList{ServiceBusReceivedMessage}" /> of messages that were peeked.</returns> private async Task <IList <ServiceBusReceivedMessage> > PeekBatchAtInternalAsync( long?sequenceNumber, int maxMessages, CancellationToken cancellationToken) { Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.PeekMessageStart(Identifier, sequenceNumber, maxMessages); IList <ServiceBusReceivedMessage> messages = null; try { messages = await InnerReceiver.PeekBatchAtAsync( sequenceNumber, maxMessages, cancellationToken) .ConfigureAwait(false); } catch (Exception exception) { ServiceBusEventSource.Log.PeekMessageException(Identifier, exception); throw; } cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.PeekMessageComplete(Identifier, maxMessages); return(messages); }
/// <summary> /// Fetches the next batch of active messages without changing the state of the receiver or the message source. /// </summary> /// <param name="sequenceNumber">The sequence number from where to peek the message.</param> /// <param name="maxMessages">The maximum number of messages that will be fetched.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// <returns>An <see cref="IList{ServiceBusReceivedMessage}" /> of messages that were peeked.</returns> private async Task <IList <ServiceBusReceivedMessage> > PeekBatchAtInternalAsync( long?sequenceNumber, int maxMessages, CancellationToken cancellationToken) { Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); Logger.PeekMessageStart(Identifier, sequenceNumber, maxMessages); using DiagnosticScope scope = _scopeFactory.CreateScope( DiagnosticProperty.PeekActivityName, requestedMessageCount: maxMessages); scope.Start(); IList <ServiceBusReceivedMessage> messages = new List <ServiceBusReceivedMessage>(); try { messages = await InnerReceiver.PeekBatchAtAsync( sequenceNumber, maxMessages, cancellationToken) .ConfigureAwait(false); } catch (Exception exception) { Logger.PeekMessageException(Identifier, exception.ToString()); scope.Failed(exception); throw; } Logger.PeekMessageComplete(Identifier, messages.Count); scope.SetMessageData(messages); return(messages); }