feat(backend): generic settings RPC bridge, LogStreamHub SignalR, and log ringbuffer
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FinlyticBackend.Hubs;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR Hub that streams live log messages from microservices to connected web UI clients.
|
||||
/// </summary>
|
||||
public class LogStreamHub : Hub
|
||||
{
|
||||
private readonly ILogger<LogStreamHub> _logger;
|
||||
|
||||
public LogStreamHub(ILogger<LogStreamHub> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task JoinServiceLogs(string serviceName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(serviceName))
|
||||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, serviceName);
|
||||
_logger.LogInformation("[LogStreamHub] Client {ConnectionId} joined log stream for {ServiceName}", Context.ConnectionId, serviceName);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LeaveServiceLogs(string serviceName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(serviceName))
|
||||
{
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, serviceName);
|
||||
_logger.LogInformation("[LogStreamHub] Client {ConnectionId} left log stream for {ServiceName}", Context.ConnectionId, serviceName);
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
_logger.LogInformation("[LogStreamHub] Client connected: {ConnectionId}", Context.ConnectionId);
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public override async Task OnDisconnectedAsync(Exception? exception)
|
||||
{
|
||||
_logger.LogInformation("[LogStreamHub] Client disconnected: {ConnectionId}", Context.ConnectionId);
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user