mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 17:53:03 +08:00
Add new interface for application message receivers
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public interface IApplicationMessageReceiver
|
||||
{
|
||||
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,10 @@ using MQTTnet.Core.Packets;
|
||||
|
||||
namespace MQTTnet.Core.Client
|
||||
{
|
||||
public interface IMqttClient
|
||||
public interface IMqttClient : IApplicationMessageReceiver
|
||||
{
|
||||
bool IsConnected { get; }
|
||||
|
||||
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
|
||||
event EventHandler<MqttClientConnectedEventArgs> Connected;
|
||||
event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ using MQTTnet.Core.Protocol;
|
||||
|
||||
namespace MQTTnet.Core.ManagedClient
|
||||
{
|
||||
public class ManagedMqttClient
|
||||
public class ManagedMqttClient : IApplicationMessageReceiver
|
||||
{
|
||||
private readonly ManagedMqttClientStorageManager _storageManager = new ManagedMqttClientStorageManager();
|
||||
private readonly BlockingCollection<MqttApplicationMessage> _messageQueue = new BlockingCollection<MqttApplicationMessage>();
|
||||
@@ -38,12 +38,12 @@ namespace MQTTnet.Core.ManagedClient
|
||||
_mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived;
|
||||
}
|
||||
|
||||
public bool IsConnected => _mqttClient.IsConnected;
|
||||
|
||||
public event EventHandler<MqttClientConnectedEventArgs> Connected;
|
||||
public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
|
||||
public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
|
||||
|
||||
public bool IsConnected => _mqttClient.IsConnected;
|
||||
|
||||
public async Task StartAsync(IManagedMqttClientOptions options)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
@@ -242,22 +242,6 @@ namespace MQTTnet.Core.ManagedClient
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsync(List<MqttApplicationMessage> messages)
|
||||
{
|
||||
if (messages == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var storage = _options.Storage;
|
||||
if (storage != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _options.Storage.SaveQueuedMessagesAsync(messages);
|
||||
}
|
||||
|
||||
private async Task PushSubscriptionsAsync()
|
||||
{
|
||||
_trace.Information(nameof(ManagedMqttClient), "Synchronizing subscriptions");
|
||||
|
||||
Reference in New Issue
Block a user