Browse Source

Add new interface for application message receivers

release/3.x.x
Christian Kratky 7 years ago
parent
commit
b52645f77a
3 changed files with 13 additions and 21 deletions
  1. +9
    -0
      MQTTnet.Core/Client/IApplicationMessageReceiver.cs
  2. +1
    -2
      MQTTnet.Core/Client/IMqttClient.cs
  3. +3
    -19
      MQTTnet.Core/ManagedClient/ManagedMqttClient.cs

+ 9
- 0
MQTTnet.Core/Client/IApplicationMessageReceiver.cs View File

@@ -0,0 +1,9 @@
using System;

namespace MQTTnet.Core.Client
{
public interface IApplicationMessageReceiver
{
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
}
}

+ 1
- 2
MQTTnet.Core/Client/IMqttClient.cs View File

@@ -5,11 +5,10 @@ using MQTTnet.Core.Packets;


namespace MQTTnet.Core.Client namespace MQTTnet.Core.Client
{ {
public interface IMqttClient
public interface IMqttClient : IApplicationMessageReceiver
{ {
bool IsConnected { get; } bool IsConnected { get; }


event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;
event EventHandler<MqttClientConnectedEventArgs> Connected; event EventHandler<MqttClientConnectedEventArgs> Connected;
event EventHandler<MqttClientDisconnectedEventArgs> Disconnected; event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;




+ 3
- 19
MQTTnet.Core/ManagedClient/ManagedMqttClient.cs View File

@@ -12,7 +12,7 @@ using MQTTnet.Core.Protocol;


namespace MQTTnet.Core.ManagedClient namespace MQTTnet.Core.ManagedClient
{ {
public class ManagedMqttClient
public class ManagedMqttClient : IApplicationMessageReceiver
{ {
private readonly ManagedMqttClientStorageManager _storageManager = new ManagedMqttClientStorageManager(); private readonly ManagedMqttClientStorageManager _storageManager = new ManagedMqttClientStorageManager();
private readonly BlockingCollection<MqttApplicationMessage> _messageQueue = new BlockingCollection<MqttApplicationMessage>(); private readonly BlockingCollection<MqttApplicationMessage> _messageQueue = new BlockingCollection<MqttApplicationMessage>();
@@ -38,12 +38,12 @@ namespace MQTTnet.Core.ManagedClient
_mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived; _mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived;
} }


public bool IsConnected => _mqttClient.IsConnected;

public event EventHandler<MqttClientConnectedEventArgs> Connected; public event EventHandler<MqttClientConnectedEventArgs> Connected;
public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected; public event EventHandler<MqttClientDisconnectedEventArgs> Disconnected;
public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived; public event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived;


public bool IsConnected => _mqttClient.IsConnected;

public async Task StartAsync(IManagedMqttClientOptions options) public async Task StartAsync(IManagedMqttClientOptions options)
{ {
if (options == null) throw new ArgumentNullException(nameof(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() private async Task PushSubscriptionsAsync()
{ {
_trace.Information(nameof(ManagedMqttClient), "Synchronizing subscriptions"); _trace.Information(nameof(ManagedMqttClient), "Synchronizing subscriptions");


Loading…
Cancel
Save