Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="retryPolicy"></param>
        /// <param name="fromSequenceNumber"></param>
        /// <param name="messageCount"></param>
        /// <param name="sessionId"></param>
        /// <param name="receiveLinkName"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <IEnumerable <ServiceBusMessage> > PeekAsync(
            ServiceBusRetryPolicy retryPolicy,
            long?fromSequenceNumber,
            int messageCount       = 1,
            string sessionId       = null,
            string receiveLinkName = null,
            CancellationToken cancellationToken = default)
        {
            RetriableContext context = new RetriableContext(
                ConnectionScope,
                new Stopwatch(),
                retryPolicy,
                EntityName,
                cancellationToken);

            return(await context.RunOperation(
                       async() => await PeekInternal(
                           context,
                           fromSequenceNumber,
                           messageCount,
                           sessionId,
                           receiveLinkName)
                       .ConfigureAwait(false))
                   .ConfigureAwait(false));
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fromSequenceNumber"></param>
        /// <param name="maxMessages"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        internal async IAsyncEnumerable <ServiceBusMessage> PeekRangeBySequenceInternal(
            long?fromSequenceNumber,
            int maxMessages = 1,
            [EnumeratorCancellation]
            CancellationToken cancellationToken = default)
        {
            RetriableContext  context    = CreateRetriableContext(cancellationToken);
            ReceivingAmqpLink openedLink =
                await context.RunOperation(
                    async() => await Consumer.ReceiveLink.GetOrCreateAsync(context.TimeSpan)
                    .ConfigureAwait(false))
                .ConfigureAwait(false);

            var source = (Source)openedLink.Settings.Source;

            if (source.FilterSet.TryGetValue <string>(AmqpClientConstants.SessionFilterName, out var tempSessionId))
            {
                // If one of the constructors not accepting a SessionId was used, the broker will determine which session to send messages from.
                SessionId = tempSessionId;
            }
            IAsyncEnumerable <ServiceBusMessage> ret = PeekRangeBySequenceInternal(
                fromSequenceNumber: fromSequenceNumber,
                maxMessages: maxMessages,
                sessionId: SessionId,
                cancellationToken: cancellationToken);

            await foreach (ServiceBusMessage msg in ret.ConfigureAwait(false))
            {
                yield return(msg);
            }
        }