| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Threading; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace Azure.Messaging.ServiceBus |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The <see cref="ProcessMessageEventArgs"/> contain event args that are specific |
| | 13 | | /// to the <see cref="ServiceBusReceivedMessage"/> that is being processed. |
| | 14 | | /// </summary> |
| | 15 | | public class ProcessMessageEventArgs : EventArgs |
| | 16 | | { |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// The received message to be processed. |
| | 20 | | /// </summary> |
| 0 | 21 | | public ServiceBusReceivedMessage Message { get; } |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// A <see cref="System.Threading.CancellationToken"/> instance to signal the request to cancel the operation. |
| | 25 | | /// </summary> |
| 0 | 26 | | public CancellationToken CancellationToken { get; } |
| | 27 | |
|
| | 28 | | private readonly ServiceBusReceiver _receiver; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the <see cref="ProcessMessageEventArgs"/> class. |
| | 32 | | /// </summary> |
| | 33 | | /// |
| | 34 | | /// <param name="message"></param> |
| | 35 | | /// <param name="receiver"></param> |
| | 36 | | /// <param name="cancellationToken"></param> |
| 8 | 37 | | internal ProcessMessageEventArgs(ServiceBusReceivedMessage message, ServiceBusReceiver receiver, CancellationTok |
| | 38 | | { |
| 8 | 39 | | Message = message; |
| 8 | 40 | | _receiver = receiver; |
| 8 | 41 | | CancellationToken = cancellationToken; |
| 8 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// |
| | 46 | | /// </summary> |
| | 47 | | /// <param name="message"></param> |
| | 48 | | /// <param name="propertiesToModify"></param> |
| | 49 | | /// <param name="cancellationToken"></param> |
| | 50 | | /// <returns></returns> |
| | 51 | | public async Task AbandonMessageAsync( |
| | 52 | | ServiceBusReceivedMessage message, |
| | 53 | | IDictionary<string, object> propertiesToModify = default, |
| | 54 | | CancellationToken cancellationToken = default) |
| | 55 | | { |
| 4 | 56 | | await _receiver.AbandonMessageAsync(message, propertiesToModify, cancellationToken) |
| 4 | 57 | | .ConfigureAwait(false); |
| 2 | 58 | | message.IsSettled = true; |
| 2 | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// |
| | 63 | | /// </summary> |
| | 64 | | /// <param name="message"></param> |
| | 65 | | /// <param name="cancellationToken"></param> |
| | 66 | | /// <returns></returns> |
| | 67 | | public async Task CompleteMessageAsync( |
| | 68 | | ServiceBusReceivedMessage message, |
| | 69 | | CancellationToken cancellationToken = default) |
| | 70 | | { |
| 4 | 71 | | await _receiver.CompleteMessageAsync( |
| 4 | 72 | | message, |
| 4 | 73 | | cancellationToken) |
| 4 | 74 | | .ConfigureAwait(false); |
| 2 | 75 | | message.IsSettled = true; |
| 2 | 76 | | } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// |
| | 80 | | /// </summary> |
| | 81 | | /// <param name="message"></param> |
| | 82 | | /// <param name="deadLetterReason"></param> |
| | 83 | | /// <param name="deadLetterErrorDescription"></param> |
| | 84 | | /// <param name="cancellationToken"></param> |
| | 85 | | /// <returns></returns> |
| | 86 | | public async Task DeadLetterMessageAsync( |
| | 87 | | ServiceBusReceivedMessage message, |
| | 88 | | string deadLetterReason, |
| | 89 | | string deadLetterErrorDescription = default, |
| | 90 | | CancellationToken cancellationToken = default) |
| | 91 | | { |
| 4 | 92 | | await _receiver.DeadLetterMessageAsync( |
| 4 | 93 | | message, |
| 4 | 94 | | deadLetterReason, |
| 4 | 95 | | deadLetterErrorDescription, |
| 4 | 96 | | cancellationToken) |
| 4 | 97 | | .ConfigureAwait(false); |
| 2 | 98 | | message.IsSettled = true; |
| 2 | 99 | | } |
| | 100 | |
|
| | 101 | | /// <summary> |
| | 102 | | /// |
| | 103 | | /// </summary> |
| | 104 | | /// <param name="message"></param> |
| | 105 | | /// <param name="propertiesToModify"></param> |
| | 106 | | /// <param name="cancellationToken"></param> |
| | 107 | | /// <returns></returns> |
| | 108 | | public async Task DeadLetterMessageAsync( |
| | 109 | | ServiceBusReceivedMessage message, |
| | 110 | | IDictionary<string, object> propertiesToModify = default, |
| | 111 | | CancellationToken cancellationToken = default) |
| | 112 | | { |
| 4 | 113 | | await _receiver.DeadLetterMessageAsync( |
| 4 | 114 | | message, |
| 4 | 115 | | propertiesToModify, |
| 4 | 116 | | cancellationToken) |
| 4 | 117 | | .ConfigureAwait(false); |
| 2 | 118 | | message.IsSettled = true; |
| 2 | 119 | | } |
| | 120 | |
|
| | 121 | | /// <summary> |
| | 122 | | /// |
| | 123 | | /// </summary> |
| | 124 | | /// <param name="message"></param> |
| | 125 | | /// <param name="propertiesToModify"></param> |
| | 126 | | /// <param name="cancellationToken"></param> |
| | 127 | | /// <returns></returns> |
| | 128 | | public async Task DeferMessageAsync( |
| | 129 | | ServiceBusReceivedMessage message, |
| | 130 | | IDictionary<string, object> propertiesToModify = default, |
| | 131 | | CancellationToken cancellationToken = default) |
| | 132 | | { |
| 4 | 133 | | await _receiver.DeferMessageAsync( |
| 4 | 134 | | message, |
| 4 | 135 | | propertiesToModify, |
| 4 | 136 | | cancellationToken) |
| 4 | 137 | | .ConfigureAwait(false); |
| 2 | 138 | | message.IsSettled = true; |
| 2 | 139 | | } |
| | 140 | | } |
| | 141 | | } |