/// <summary> /// Moves a message to the deadletter sub-queue. /// </summary> /// /// <param name="message">The <see cref="ServiceBusReceivedMessage"/> to deadletter.</param> /// <param name="propertiesToModify">The properties of the message to modify while moving to sub-queue.</param> /// <param name="cancellationToken"></param> /// /// <remarks> /// In order to receive a message from the deadletter queue, you will need a new /// <see cref="ServiceBusReceiver"/> with the corresponding path. /// You can use EntityNameHelper.FormatDeadLetterPath(string)"/> to help with this. /// 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 DeadLetterAsync( ServiceBusReceivedMessage message, IDictionary <string, object> propertiesToModify = null, CancellationToken cancellationToken = default) { Argument.AssertNotClosed(IsClosed, nameof(ServiceBusReceiver)); ThrowIfNotPeekLockMode(); await _innerReceiver.DeadLetterAsync( message : message, propertiesToModify : propertiesToModify, cancellationToken : cancellationToken).ConfigureAwait(false); }
/// <summary> /// Moves a message to the deadletter sub-queue. /// </summary> /// /// <param name="lockToken">The lock token <see cref="ServiceBusReceivedMessage"/> to deadletter.</param> /// <param name="deadLetterReason">The reason for deadlettering the message.</param> /// <param name="deadLetterErrorDescription">The error description for deadlettering the message.</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 a message from the deadletter queue, you will need a new <see cref="ServiceBusReceiver"/>, with the corresponding path. /// You can use EntityNameHelper.FormatDeadLetterPath(string) to help with this. /// This operation can only be performed on messages that were received by this receiver. /// </remarks> private async Task DeadLetterInternalAsync( string lockToken, string deadLetterReason = default, string deadLetterErrorDescription = default, IDictionary <string, object> propertiesToModify = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(lockToken, nameof(lockToken)); Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ThrowIfNotPeekLockMode(); ServiceBusEventSource.Log.DeadLetterMessageStart(Identifier, 1, lockToken); try { await InnerReceiver.DeadLetterAsync( lockToken : lockToken, deadLetterReason : deadLetterReason, deadLetterErrorDescription : deadLetterErrorDescription, propertiesToModify : propertiesToModify, cancellationToken : cancellationToken).ConfigureAwait(false); } catch (Exception exception) { ServiceBusEventSource.Log.DeadLetterMessageException(Identifier, exception); throw; } cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.DeadLetterMessageComplete(Identifier); }
/// <summary> /// Moves a message to the deadletter sub-queue. /// </summary> /// /// <param name="lockToken">The lock token <see cref="ServiceBusReceivedMessage"/> to deadletter.</param> /// <param name="deadLetterReason">The reason for deadlettering the message.</param> /// <param name="deadLetterErrorDescription">The error description for deadlettering the message.</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 a message from the deadletter queue, you will need a new <see cref="ServiceBusReceiver"/>, with the corresponding path. /// You can use EntityNameHelper.FormatDeadLetterPath(string) to help with this. /// This operation can only be performed on messages that were received by this receiver. /// </remarks> private async Task DeadLetterInternalAsync( string lockToken, string deadLetterReason = default, string deadLetterErrorDescription = default, IDictionary <string, object> propertiesToModify = default, CancellationToken cancellationToken = default) { ThrowIfLockTokenIsEmpty(lockToken); Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ThrowIfNotPeekLockMode(); Logger.DeadLetterMessageStart(Identifier, 1, lockToken); using DiagnosticScope scope = _scopeFactory.CreateScope( DiagnosticProperty.DeadLetterActivityName, lockToken: lockToken); scope.Start(); try { await InnerReceiver.DeadLetterAsync( lockToken : lockToken, deadLetterReason : deadLetterReason, deadLetterErrorDescription : deadLetterErrorDescription, propertiesToModify : propertiesToModify, cancellationToken : cancellationToken).ConfigureAwait(false); } catch (Exception exception) { Logger.DeadLetterMessageException(Identifier, exception.ToString()); scope.Failed(exception); throw; } Logger.DeadLetterMessageComplete(Identifier); }