MQTTnet.Agent 1.0.6

dotnet add package MQTTnet.Agent --version 1.0.6                
NuGet\Install-Package MQTTnet.Agent -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MQTTnet.Agent" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MQTTnet.Agent --version 1.0.6                
#r "nuget: MQTTnet.Agent, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MQTTnet.Agent as a Cake Addin
#addin nuget:?package=MQTTnet.Agent&version=1.0.6

// Install MQTTnet.Agent as a Cake Tool
#tool nuget:?package=MQTTnet.Agent&version=1.0.6                

MQTTnet.Agent MQTT 消息代理

概述

目标

  1. 建立类型化 订阅/发布接口
  2. 通过 Pub/Sub 接口 简化 MQTTnet Client 消息订阅和发布方法

接口定义

消息订阅接口

  • IMessageReader
    • 接口返回 ChannelReader<T> 方便异步处理消息
/// <summary>
/// MQTT 消息读取 Channel
/// </summary>
public interface IMessageReader {
    /// <summary>
    /// 订阅消息
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    /// <param name="topic">订阅主题</param>
    /// <param name="cancellationToken"></param>
    Task<ChannelReader<MessageArgs<T>>> GetChannelAsync<T>(string topic, CancellationToken cancellationToken = default) where T : class;
}
  • IMessageSubscriber
    • Reactive 风格的订阅接口
/// <summary>
/// 消息订阅器
/// </summary>
public interface IMessageSubscriber : IDisposable {

    /// <summary>
    /// 订阅主题
    /// </summary>
    /// <typeparam name="T"></typeparam>
    Task<IObservable<MessageArgs<T>>> SubscribeAsync<T>(string topic, CancellationToken cancellationToken = default) where T : class;

    /// <summary>
    /// 包含处理程序的主题订阅
    /// </summary>
    /// <typeparam name="T">订阅消息类型</typeparam>
    Task<IDisposable> SubscribeAsync<T>(string topic, Action<MessageArgs<T>> onNext, CancellationToken cancellationToken = default) where T : class;
}
  • 发布接口
public interface IMessagePublisher {
    /// <summary>
    /// 发布消息
    /// </summary>
    /// <param name="topic">发布主题</param>
    /// <param name="payload">载荷对象</param>
    /// <param name="retain">消息保留标志,默认为 <see langword="false"/></param>
    /// <param name="options"></param>
    /// <param name="cancellationToken"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    Task PublishAsync<T>(string topic, T? payload, JsonSerializerOptions? options = null, bool retain = false, CancellationToken cancellationToken = default(CancellationToken)) where T : class;

    /// <summary>
    /// 发布文本消息
    /// </summary>
    /// <param name="topic">发布主题</param>
    /// <param name="payload">载荷内容</param>
    /// <param name="retain">消息保留标志,默认为 <see langword="false"/></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task PublishStringAsync(string topic, string payload, bool retain = false, CancellationToken cancellationToken = default(CancellationToken));
}
  • 合并接口
public interface IMessageAgent : IMessageReader, IMessagePublisher, IDisposable {

}

public interface IMessageHub : IMessageSubscriber, IMessagePublisher {

}

ChangeLog

v1.0.4

  • 消息发布增加 QOS 支持
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 118 11/28/2024
1.0.6-build-20231222 350 12/22/2023
1.0.5 660 12/22/2023
1.0.4 355 11/27/2023
1.0.3 474 5/5/2023
1.0.2-Build- 134 5/6/2023
1.0.1-build-20230207 303 2/7/2023
1.0.0 683 1/16/2023