Esempio n. 1
0
        /// <summary> Indicates that the receiver wants to defer the processing for the message.</summary>
        ///
        /// <param name="lockToken">The lockToken of the <see cref="ServiceBusReceivedMessage"/> to defer.</param>
        /// <param name="propertiesToModify">The properties of the message to modify while deferring the message.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>
        /// A lock token can be found in <see cref="ServiceBusReceivedMessage.LockToken"/>,
        /// only when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
        /// In order to receive this message again in the future, you will need to save the <see cref="ServiceBusReceivedMessage.SequenceNumber"/>
        /// and receive it using <see cref="ReceiveDeferredMessageAsync(long, CancellationToken)"/>.
        /// Deferring messages does not impact message's expiration, meaning that deferred messages can still expire.
        /// This operation can only be performed on messages that were received by this receiver.
        /// </remarks>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        public virtual async Task DeferAsync(
            string lockToken,
            IDictionary <string, object> propertiesToModify = null,
            CancellationToken cancellationToken             = default)
        {
            ThrowIfLockTokenIsEmpty(lockToken);
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
            ThrowIfNotPeekLockMode();
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            Logger.DeferMessageStart(Identifier, 1, lockToken);
            using DiagnosticScope scope = _scopeFactory.CreateScope(
                      DiagnosticProperty.DeferActivityName,
                      lockToken: lockToken);
            scope.Start();

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

            Logger.DeferMessageComplete(Identifier);
        }
Esempio n. 2
0
        /// <summary> Indicates that the receiver wants to defer the processing for the message.</summary>
        ///
        /// <param name="lockToken">The lockToken of the <see cref="ServiceBusReceivedMessage"/> to defer.</param>
        /// <param name="propertiesToModify">The properties of the message to modify while deferring the message.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <remarks>
        /// A lock token can be found in <see cref="ServiceBusReceivedMessage.LockToken"/>,
        /// only when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
        /// In order to receive this message again in the future, you will need to save the <see cref="ServiceBusReceivedMessage.SequenceNumber"/>
        /// and receive it using <see cref="ReceiveDeferredMessageAsync(long, CancellationToken)"/>.
        /// Deferring messages does not impact message's expiration, meaning that deferred messages can still expire.
        /// This operation can only be performed on messages that were received by this receiver.
        /// </remarks>
        ///
        /// <returns>A task to be resolved on when the operation has completed.</returns>
        public virtual async Task DeferAsync(
            string lockToken,
            IDictionary <string, object> propertiesToModify = null,
            CancellationToken cancellationToken             = default)
        {
            Argument.AssertNotNull(lockToken, nameof(lockToken));
            Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver));
            ThrowIfNotPeekLockMode();
            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.DeferMessageStart(Identifier, 1, lockToken);

            try
            {
                await InnerReceiver.DeferAsync(
                    lockToken,
                    propertiesToModify,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ServiceBusEventSource.Log.DeferMessageException(Identifier, ex);
                throw;
            }

            cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>();
            ServiceBusEventSource.Log.DeferMessageComplete(Identifier);
        }
 /// <summary>Indicates that the receiver wants to defer the processing for the message.</summary>
 ///
 /// <param name="message">The lock token of the <see cref="ServiceBusMessage" />.</param>
 /// <param name="propertiesToModify">The properties of the message to modify while deferring the message.</param>
 /// <param name="cancellationToken"></param>
 ///
 /// <remarks>
 /// A lock token can be found in <see cref="ServiceBusReceivedMessage.LockToken"/>,
 /// only when <see cref="ReceiveMode"/> is set to <see cref="ReceiveMode.PeekLock"/>.
 /// In order to receive this message again in the future, you will need to save the <see cref="ServiceBusReceivedMessage.SequenceNumber"/>
 /// and receive it using <see cref="ReceiveDeferredMessageAsync(long, CancellationToken)"/>.
 /// Deferring messages does not impact message's expiration, meaning that deferred messages can still expire.
 /// This operation can only be performed on messages that were received by this receiver.
 /// </remarks>
 public virtual async Task DeferAsync(
     ServiceBusReceivedMessage message,
     IDictionary <string, object> propertiesToModify = null,
     CancellationToken cancellationToken             = default)
 {
     Argument.AssertNotClosed(IsClosed, nameof(ServiceBusReceiver));
     ThrowIfNotPeekLockMode();
     await _innerReceiver.DeferAsync(
         message,
         propertiesToModify,
         cancellationToken).ConfigureAwait(false);
 }