Files
Finlytic/FinlyticBackend/Util/WebMqttClient.cs
T

45 lines
1.4 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace FinlyticBackend.Util;
/// <summary>
/// Backward-compatible bridge forwarding RPC requests to the primary singleton <see cref="BackendMqttBridge"/>.
/// Prevents secondary MQTT connection instantiations in the gateway process.
/// </summary>
public class WebMqttClient : IHostedService
{
private readonly BackendMqttBridge _bridge;
public bool IsConnected => _bridge.IsConnected;
public WebMqttClient(BackendMqttBridge bridge)
{
_bridge = bridge;
}
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task<TResponse?> SendRpcRequestAsync<TResponse, TRequest>(string channel, TRequest request, TimeSpan timeout)
where TResponse : class
where TRequest : class
{
return _bridge.SendRpcRequestAsync<TResponse, TRequest>(channel, request, timeout);
}
public Task<TResponse?> SendRpcRequestAsync<TResponse, TRequest>(string channel, TRequest request)
where TResponse : class
where TRequest : class
{
return _bridge.SendRpcRequestAsync<TResponse, TRequest>(channel, request);
}
public Task PublishAsync<T>(string topic, T payload)
{
return _bridge.PublishAsync(topic, payload);
}
}