/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Middleware/SetPartitionKeyFilter.cs
33 строки
996 B
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.Middleware { using System.Threading.Tasks; using Transports; public class SetPartitionKeyFilter<TMessage> : IFilter<SendContext<TMessage>> where TMessage : class { readonly IMessagePartitionKeyFormatter<TMessage> _routingKeyFormatter; public SetPartitionKeyFilter(IMessagePartitionKeyFormatter<TMessage> routingKeyFormatter) { _routingKeyFormatter = routingKeyFormatter; } public Task Send(SendContext<TMessage> context, IPipe<SendContext<TMessage>> next) { var routingKey = _routingKeyFormatter.FormatPartitionKey(context); if (context.TryGetPayload(out PartitionKeySendContext routingKeySendContext)) routingKeySendContext.PartitionKey = routingKey; return next.Send(context); } public void Probe(ProbeContext context) { context.CreateFilterScope("setPartitionKey"); } } }