コード例 #1
0
        /// <summary>
        /// Completes a <see cref="ServiceBusReceivedMessage"/>. This will delete the message from the service.
        /// </summary>
        ///
        /// <param name="lockToken">The lock token of the <see cref="ServiceBusReceivedMessage"/> message to complete.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>
        /// This operation can only be performed on a message that was received by this receiver
        /// when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
        /// </remarks>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        public virtual async Task CompleteAsync(
            string lockToken,
            CancellationToken cancellationToken = default)
        {
            ThrowIfLockTokenIsEmpty(lockToken);
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
            Argument.AssertNotNullOrEmpty(lockToken, nameof(lockToken));
            ThrowIfNotPeekLockMode();
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.CompleteMessageStart(
                Identifier,
                1,
                lockToken);
            using DiagnosticScope scope = _scopeFactory.CreateScope(
                      DiagnosticProperty.CompleteActivityName,
                      lockToken: lockToken);
            scope.Start();

            try
            {
                await InnerReceiver.CompleteAsync(
                    lockToken,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                Logger.CompleteMessageException(Identifier, exception.ToString());
                scope.Failed(exception);
                throw;
            }

            Logger.CompleteMessageComplete(Identifier);
        }
コード例 #2
0
        /// <summary>
        /// Completes a series of <see cref="ServiceBusReceivedMessage"/>. This will delete the message from the service.
        /// </summary>
        ///
        /// <param name="lockTokens">An <see cref="IEnumerable{T}"/> containing the lock tokens of the corresponding messages to complete.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>
        /// This operation can only be performed on messages that were received by this receiver
        /// when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
        /// </remarks>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        internal virtual async Task CompleteAsync(
            IEnumerable <string> lockTokens,
            CancellationToken cancellationToken = default)
        {
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
            Argument.AssertNotNullOrEmpty(lockTokens, nameof(lockTokens));
            ThrowIfNotPeekLockMode();
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            var lockTokenList = lockTokens.ToList();

            ServiceBusEventSource.Log.CompleteMessageStart(Identifier, lockTokenList.Count, lockTokenList);

            try
            {
                await InnerReceiver.CompleteAsync(
                    lockTokenList,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                ServiceBusEventSource.Log.CompleteMessageException(Identifier, exception);
                throw;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.CompleteMessageComplete(Identifier);
        }
コード例 #3
0
 /// <summary>
 /// Completes a series of <see cref="ServiceBusMessage"/>. This will delete the message from the service.
 /// </summary>
 ///
 /// <param name="receivedMessages">An <see cref="IEnumerable{T}"/> containing the list of <see cref="ServiceBusReceivedMessage"/> messages to complete.</param>
 /// <param name="cancellationToken"></param>
 ///
 /// <remarks>
 /// This operation can only be performed on messages that were received by this receiver
 /// when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
 /// </remarks>
 public virtual async Task CompleteAsync(
     IEnumerable <ServiceBusReceivedMessage> receivedMessages,
     CancellationToken cancellationToken = default)
 {
     Argument.AssertNotClosed(IsClosed, nameof(ServiceBusReceiver));
     ThrowIfNotPeekLockMode();
     await _innerReceiver.CompleteAsync(
         receivedMessages,
         cancellationToken).ConfigureAwait(false);
 }