forked from zarusz/SlimMessageBus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIServiceBusConsumerErrorHandler.cs
50 lines (42 loc) · 1.64 KB
/
IServiceBusConsumerErrorHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace SlimMessageBus.Host.AzureServiceBus;
public interface IServiceBusConsumerErrorHandler<in T> : IConsumerErrorHandler<T>;
public abstract class ServiceBusConsumerErrorHandler<T> : ConsumerErrorHandler<T>, IServiceBusConsumerErrorHandler<T>
{
public ProcessResult DeadLetter(string reason = null, string description = null)
{
return reason == null && description == null
? ServiceBusProcessResult.DeadLetter
: new ServiceBusProcessResult.DeadLetterState(reason, description);
}
public ProcessResult Failure(IReadOnlyDictionary<string, object> properties)
{
return properties != null && properties.Count > 0
? new ServiceBusProcessResult.FailureStateWithProperties(properties)
: Failure();
}
}
public record ServiceBusProcessResult : ProcessResult
{
/// <summary>
/// The message must be sent to the dead letter queue.
/// </summary>
public static readonly ProcessResult DeadLetter = new DeadLetterState();
public record DeadLetterState : ProcessResult
{
public DeadLetterState(string reason = null, string description = null)
{
Reason = reason;
Description = description;
}
public string Reason { get; }
public string Description { get; }
}
public record FailureStateWithProperties : FailureState
{
public FailureStateWithProperties(IReadOnlyDictionary<string, object> properties)
{
Properties = properties;
}
public IReadOnlyDictionary<string, object> Properties { get; }
}
}