/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Middleware/Partition.cs
65 строк
2 KB
Chris Patterson
Integration of all external packages into MassTransit, split out into Abstractions, Middleware, and the core MassTransit assembly.
22 янв 2022, 18:24
22 янв 2022, 18:24
b5b4f50
Код
Авторство
О чём код?
namespace MassTransit.Middleware { using System; using System.Threading; using System.Threading.Tasks; public class Partition : IAsyncDisposable { readonly int _index; readonly SemaphoreSlim _limit; long _attemptCount; long _failureCount; long _successCount; public Partition(int index) { _index = index; _limit = new SemaphoreSlim(1); } public async ValueTask DisposeAsync() { await _limit.WaitAsync().ConfigureAwait(false); _limit.Dispose(); } public void Probe(ProbeContext context) { var partitionScope = context.CreateScope($"partition-{_index}"); partitionScope.Set(new { AttemptCount = _attemptCount, SuccessCount = _successCount, FailureCount = _failureCount }); } public async Task Send<T>(T context, IPipe<T> next) where T : class, PipeContext { await _limit.WaitAsync(context.CancellationToken).ConfigureAwait(false); try { Interlocked.Increment(ref _attemptCount); await next.Send(context).ConfigureAwait(false); Interlocked.Increment(ref _successCount); } catch { Interlocked.Increment(ref _failureCount); throw; } finally { _limit.Release(); } } } }