Files
git.stella-ops.org/src/Signals/StellaOps.Signals/Services/InMemoryEventsPublisher.cs
StellaOps Bot bc0762e97d up
2025-12-09 00:20:52 +02:00

40 lines
1.4 KiB
C#

using System;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using StellaOps.Signals.Models;
namespace StellaOps.Signals.Services;
/// <summary>
/// Placeholder events publisher; replace with real bus integration when contracts are finalized.
/// </summary>
internal sealed class InMemoryEventsPublisher : IEventsPublisher
{
private readonly ILogger<InMemoryEventsPublisher> logger;
private readonly ReachabilityFactEventBuilder eventBuilder;
private static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web)
{
WriteIndented = false,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};
public InMemoryEventsPublisher(ILogger<InMemoryEventsPublisher> logger, ReachabilityFactEventBuilder eventBuilder)
{
this.logger = logger;
this.eventBuilder = eventBuilder ?? throw new ArgumentNullException(nameof(eventBuilder));
}
public Task PublishFactUpdatedAsync(ReachabilityFactDocument fact, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(fact);
var envelope = eventBuilder.Build(fact);
var json = JsonSerializer.Serialize(envelope, SerializerOptions);
logger.LogInformation(json);
return Task.CompletedTask;
}
}