/
ErrorQueueSettings.cs
61 lines (52 loc) · 2.31 KB
/
ErrorQueueSettings.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
51
52
53
54
55
56
57
58
59
60
61
namespace NServiceBus;
using System;
using Logging;
using Settings;
/// <summary>
/// Utility class used to find the configured error queue for an endpoint.
/// </summary>
public static class ErrorQueueSettings
{
/// <summary>
/// Finds the configured error queue for an endpoint.
/// The error queue can be configured in code using 'EndpointConfiguration.SendFailedMessagesTo()'.
/// </summary>
/// <param name="settings">The configuration settings of this endpoint.</param>
/// <returns>The configured error queue of the endpoint.</returns>
/// <exception cref="Exception">When the configuration for the endpoint is invalid.</exception>
public static string ErrorQueueAddress(this IReadOnlySettings settings)
{
ArgumentNullException.ThrowIfNull(settings);
if (TryGetExplicitlyConfiguredErrorQueueAddress(settings, out var errorQueue))
{
return errorQueue;
}
return DefaultErrorQueueName;
}
/// <summary>
/// Gets the explicitly configured error queue address if one is defined.
/// The error queue can be configured in code by using 'EndpointConfiguration.SendFailedMessagesTo()'.
/// </summary>
/// <param name="settings">The configuration settings of this endpoint.</param>
/// <param name="errorQueue">The configured error queue.</param>
/// <returns>True if an error queue has been explicitly configured.</returns>
/// <exception cref="Exception">When the configuration for the endpoint is invalid.</exception>
public static bool TryGetExplicitlyConfiguredErrorQueueAddress(this IReadOnlySettings settings, out string errorQueue)
{
ArgumentNullException.ThrowIfNull(settings);
if (settings.HasExplicitValue(SettingsKey))
{
Logger.Debug("Error queue retrieved from code configuration via 'EndpointConfiguration.SendFailedMessagesTo()'.");
errorQueue = settings.Get<string>(SettingsKey);
return true;
}
errorQueue = null;
return false;
}
/// <summary>
/// The settings key where the error queue address is stored.
/// </summary>
public const string SettingsKey = "errorQueue";
const string DefaultErrorQueueName = "error";
static readonly ILog Logger = LogManager.GetLogger(typeof(ErrorQueueSettings));
}