mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
Refactor subscribe and unsubscribe to support MQTTv5.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MQTTnet.Client.Receiving
|
||||
{
|
||||
public interface IMqttApplicationMessageHandler
|
||||
{
|
||||
Task HandleApplicationMessageAsync(MqttApplicationMessageHandlerContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MQTTnet.Client.Receiving
|
||||
{
|
||||
public class MqttApplicationMessageHandlerContext
|
||||
{
|
||||
public MqttApplicationMessageHandlerContext(string senderClientId, MqttApplicationMessage applicationMessage)
|
||||
{
|
||||
SenderClientId = senderClientId;
|
||||
ApplicationMessage = applicationMessage;
|
||||
}
|
||||
|
||||
public string SenderClientId { get; }
|
||||
|
||||
public MqttApplicationMessage ApplicationMessage { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MQTTnet.Client.Receiving
|
||||
{
|
||||
public class MqttApplicationMessageHandlerDelegate : IMqttApplicationMessageHandler
|
||||
{
|
||||
private readonly Func<MqttApplicationMessageHandlerContext, Task> _handler;
|
||||
|
||||
public MqttApplicationMessageHandlerDelegate(Action<MqttApplicationMessageHandlerContext> handler)
|
||||
{
|
||||
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||
|
||||
_handler = context =>
|
||||
{
|
||||
handler(context);
|
||||
return Task.FromResult(0);
|
||||
};
|
||||
}
|
||||
|
||||
public MqttApplicationMessageHandlerDelegate(Func<MqttApplicationMessageHandlerContext, Task> handler)
|
||||
{
|
||||
_handler = handler ?? throw new ArgumentNullException(nameof(handler));
|
||||
}
|
||||
|
||||
public Task HandleApplicationMessageAsync(MqttApplicationMessageHandlerContext context)
|
||||
{
|
||||
return _handler(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user