/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Configuration/PartitionKeyConventionExtensions.cs
57 строк
2 KB
Chris Patterson
Standardized the topology for partition key across service bus, event hub, and the SQL transport
25 апр 2024, 21:50
25 апр 2024, 21:50
e7c59ea
Код
Авторство
О чём код?
namespace MassTransit { using System; using Configuration; using Transports; public static class PartitionKeyConventionExtensions { public static void UsePartitionKeyFormatter<T>(this IMessageSendTopologyConfigurator<T> configurator, IMessagePartitionKeyFormatter<T> formatter) where T : class { configurator.UpdateConvention<IPartitionKeyMessageSendTopologyConvention<T>>(update => { update.SetFormatter(formatter); return update; }); } /// <summary> /// Use the partition key formatter for the specified message type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="configurator"></param> /// <param name="formatter"></param> public static void UsePartitionKeyFormatter<T>(this ISendTopologyConfigurator configurator, IMessagePartitionKeyFormatter<T> formatter) where T : class { configurator.GetMessageTopology<T>().UsePartitionKeyFormatter(formatter); } /// <summary> /// Use the delegate to format the partition key, using Empty if the string is null upon return /// </summary> /// <typeparam name="T"></typeparam> /// <param name="configurator"></param> /// <param name="formatter"></param> public static void UsePartitionKeyFormatter<T>(this ISendTopologyConfigurator configurator, Func<SendContext<T>, string> formatter) where T : class { configurator.GetMessageTopology<T>().UsePartitionKeyFormatter(new DelegatePartitionKeyFormatter<T>(formatter)); } /// <summary> /// Use the delegate to format the partition key, using Empty if the string is null upon return /// </summary> /// <typeparam name="T"></typeparam> /// <param name="configurator"></param> /// <param name="formatter"></param> public static void UsePartitionKeyFormatter<T>(this IMessageSendTopologyConfigurator<T> configurator, Func<SendContext<T>, string> formatter) where T : class { configurator.UsePartitionKeyFormatter(new DelegatePartitionKeyFormatter<T>(formatter)); } } }