Mark van Renswoude
bcdb376256
Added test for publish overflows Removed support for Unity Container Changed third party package references to ranges Fixed XML documentation
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Tapeti.Default
|
|
{
|
|
/// <summary>
|
|
/// IExchangeStrategy implementation which uses the first identifier in the namespace in lower case,
|
|
/// skipping the first identifier if it is 'Messaging'.
|
|
/// </summary>
|
|
/// <example>
|
|
/// Messaging.Service.Optional.Further.Parts will result in the exchange name 'service'.
|
|
/// </example>
|
|
public class NamespaceMatchExchangeStrategy : IExchangeStrategy
|
|
{
|
|
private static readonly Regex NamespaceRegex = new("^(Messaging\\.)?(?<exchange>[^\\.]+)", RegexOptions.Compiled | RegexOptions.Singleline);
|
|
|
|
|
|
/// <inheritdoc />
|
|
public string GetExchange(Type messageType)
|
|
{
|
|
if (messageType.Namespace == null)
|
|
throw new ArgumentException($"{messageType.FullName} does not have a namespace");
|
|
|
|
var match = NamespaceRegex.Match(messageType.Namespace);
|
|
if (!match.Success)
|
|
throw new ArgumentException($"Namespace for {messageType.FullName} does not match the specified format");
|
|
|
|
return match.Groups["exchange"].Value.ToLower();
|
|
}
|
|
}
|
|
}
|