// Licensed to Timothy Schenk under the GNU AGPL Version 3 License. using System.Diagnostics; using Continuity.AuthServer.Packets; using JetBrains.Annotations; using MassTransit; using Rai.PacketMediator; using Wonderking.Packets; namespace Continuity.AuthServer.Consumers; [UsedImplicitly] public class PacketConsumer : IConsumer, IDisposable { private readonly ActivitySource _activitySource; private readonly PacketDistributorService _distributorService; public PacketConsumer(PacketDistributorService distributorService) { _distributorService = distributorService; _activitySource = new ActivitySource(nameof(PacketConsumer)); } public Task Consume(ConsumeContext context) { using var activity = _activitySource?.StartActivity("PacketConsumption"); activity?.SetTag("PacketId", context.Message.OperationCode.ToString()); activity?.SetTag("SessionId", context.Message.Session.Id.ToString()); activity?.SetTag("PacketSize", context.Message.MessageBody.Length); return _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode, context.Message.Session); } public void Dispose() { _activitySource.Dispose(); GC.SuppressFinalize(this); } }