Hanson.Mqtt.Utils 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hanson.Mqtt.Utils --version 1.0.0                
NuGet\Install-Package Hanson.Mqtt.Utils -Version 1.0.0                
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="Hanson.Mqtt.Utils" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hanson.Mqtt.Utils --version 1.0.0                
#r "nuget: Hanson.Mqtt.Utils, 1.0.0"                
#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 Hanson.Mqtt.Utils as a Cake Addin
#addin nuget:?package=Hanson.Mqtt.Utils&version=1.0.0

// Install Hanson.Mqtt.Utils as a Cake Tool
#tool nuget:?package=Hanson.Mqtt.Utils&version=1.0.0                

README

Hanson.Mqtt.Utils

功能說明

簡化 MQTT 的使用方式

主要功能

  1. Broker

    • 支援 Client 上線及下線異動的處理事件
    • 支援 Client 訂閱及解除訂閱異動的處理事件
    • 支援 StartAsync 啟動 Broker
    • 支援 取得所有線上 client id
  2. Publish/Subscrib

    • 支援 Pushlish MQTT 訊息
    • 支援 Subscrib MQTT 訊息
  3. 限制

    • 限使用 本機 IP 啟動 Broker Server

安裝方式

使用範例

  • Broker Server
// 使用 SimpleFactory 建立 Broker Server

using (var server = SimpleFactory.GetBrokerServer())
{
   server.OnClientConnectedEvent += ((x) =>
        {
            _logger.Info($"使用者:{x} 已上線");
        });
   server.OnClientDisconnectedEvent += ((x) =>
        {
            _logger.Info($"使用者:{x} 已下線");
        });
   server.OnInterceptingPublishEvent += ((client, payload) =>
        {
            _logger.Info($"接收使用者:{client} 上傳的Topic:{payload.Topic}, message:{payload.Value}");
        });
   Console.WriteLine("Start MQTTnet Server ...");
   await server.StartAsync();
}
  • Publish 使用範例
var config = new MqttConfig
        {
            Host = "127.0.0.1",
            Port = 1883,
            ClientId = "publish"
        };
using (var client = SimpleFactory.CreateInstance(config))
{
	client.OnPublishAcknowledgedEvent += ((x) =>
    {
        _logger.Info($"Send topic:{x.Topic} is success");
    });
    client.OnPublishMessageTimeoutEvent += ((x) =>
    {
        _logger.Info($"Send topic:{x.Topic} is timeout");
    });        
   	var msg = Console.ReadLine();
    var payload = new Payload
        {
          Topic = "test",
          Value = "message"
         };
    await client.PublishAsync(payload);
}
  • Subscribe 使用範例
var config = new MqttConfig
        {
            Host = "127.0.0.1",
            Port = 1883,
            ClientId = "subscribe"
        };
using (var client = SimpleFactory.CreateInstance(config))
{
	client.OnMessageReceivedEvent += ((x) =>
    {
        _logger.Info($"Topic:{x.Topic}, Message value: {x.Value}");
    });
      
   	await client.SubscribeAsync("test");
}
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 was computed.  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 was computed.  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
2.0.0 117 3/21/2024
1.0.0 157 8/10/2023