/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit.Abstractions/Contexts/PartitionKeyExtensions.cs
44 строки
1 KB
Chris Patterson
Merging the SQL transport into the main codebase
09 янв 2024, 05:23
09 янв 2024, 05:23
e1eb39e
Код
Авторство
О чём код?
namespace MassTransit; using System; public static class PartitionKeyExtensions { public static string? PartitionKey(this ConsumeContext context) { return context.TryGetPayload(out PartitionKeyConsumeContext? consumeContext) ? consumeContext.PartitionKey : string.Empty; } public static string? PartitionKey(this SendContext context) { return context.TryGetPayload(out PartitionKeySendContext? sendContext) ? sendContext.PartitionKey : string.Empty; } /// <summary> /// Sets the routing key for this message /// </summary> /// <param name="context"></param> /// <param name="routingKey">The routing key for this message</param> public static void SetPartitionKey(this SendContext context, string? routingKey) { if (!context.TryGetPayload(out PartitionKeySendContext? sendContext)) throw new ArgumentException("The SendPartitionKeyContext was not available"); sendContext.PartitionKey = routingKey; } /// <summary> /// Sets the routing key for this message /// </summary> /// <param name="context"></param> /// <param name="routingKey">The routing key for this message</param> public static bool TrySetPartitionKey(this SendContext context, string? routingKey) { if (!context.TryGetPayload(out PartitionKeySendContext? sendContext)) return false; sendContext.PartitionKey = routingKey; return true; } }