ZY.MQTT 1.0.5

dotnet add package ZY.MQTT --version 1.0.5
                    
NuGet\Install-Package ZY.MQTT -Version 1.0.5
                    
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="ZY.MQTT" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZY.MQTT" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="ZY.MQTT" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZY.MQTT --version 1.0.5
                    
#r "nuget: ZY.MQTT, 1.0.5"
                    
#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.
#:package ZY.MQTT@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZY.MQTT&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=ZY.MQTT&version=1.0.5
                    
Install as a Cake Tool

MQTT

nuget引用组件 :ZY.MQTT

配置


	"Mqtt": {
    "IsServer": false,
    "Server": {
    },
    "Client": { //客户端配置
      "Server_IP": "10.0.204.10", //服务端IP
      "Server_Port": "1883", //服务端口
      "UserName": "admin", //账号
      "UserPwd": "admin", //密码
      "ClientID": "1001", //注册客户端id
      "Topic": [ "+/device/message/up/ivs_result", "/+/user/update", "/+/+/user/update" ]
    }
  }

添加Startup

1、在ConfigureServices 添加代码

	 services.AddMQTT()

2、在Configure添加代码

	

调用

       //接收消息
       _mqtt = _provider.GetService<IMqttManager>();
       _mqtt.SubscriberMessage += OnMessage;

        public async Task OnMessage(string topic,string data)
        {
        }

       //发送消息
       _mqtt = _provider.GetService<IMqttManager>();
       _mqtt.PublishData(data, $"/{robotid}/user/get");

发布订阅规则

标准发布订阅

       发布主题
       12345/device/message/up/ivs_result

       订阅主题
       12345/device/message/up/ivs_result

订阅多个主题

       发布主题
       1/device/message/up/ivs_result       2/device/message/up/ivs_result
       订阅主题
       +/device/message/up/ivs_result

       发布主题
       /hx/1/device/message/up/ivs_result       /zs/2/device/message/up/ivs_result
       订阅主题
       /+/+/device/message/up/ivs_result


       发布主题
       /hx/1/device/message/up/ivs_result/1/2       /zs/2/device/message/up/ivs_result/2/4
       订阅主题
       /+/+/device/message/up/ivs_result/#

共享订阅 (EMQX)

在订阅主题时 加前缀 $share/g1/ 同一个分组,只会有一台设备接收处理,有两个订阅分组,则分别会有两个分组内各有一台设备接收处理

       发布主题
       1/device/message/up/ivs_result       2/device/message/up/ivs_result
       订阅主题
       $share/g1/+/device/message/up/ivs_result

       发布主题
       /hx/1/device/message/up/ivs_result       /zs/2/device/message/up/ivs_result
       订阅主题
       $share/g1//+/+/device/message/up/ivs_result
       $share/g2//+/+/device/message/up/ivs_result

共享订阅客户端接收处理示意图

                      ----- client1
                      |---- client2
msg ----server---分组1----- client3                 1-5 中某一客户端接收处理    
                      |---- client4
                      ----- client5

                      
                          ----- client1
                          |---- client2
                  ---分组1----- client3           1-5 中某一客户端接收处理
                  |       |---- client4
                  |       ----- client5
msg ----server----|                                 
                  |       ----- client6
                  |       |---- client7
                  ---分组2----- client8           6-10 中某一客户端接收处理
                          |---- client9
                          ----- client10


EMQX

主题重写


     动作类型       Publish & Subscribe

     原始主题       +/device/message/up/ivs_result

     正则表达式     ^(.*)$

     目标主题      Parking/MqttClient/ivs_result
     

共享订阅

同非共享订阅一样,共享订阅包含一个主题过滤器和订阅选项,唯一的区别在于共享订阅的主题过滤器格式必须是 $share/{ShareName}/{filter} 这种形式。这几个的字段的含义分别是:

  • $share 前缀表明这将是一个共享订阅

  • {ShareName} 是一个不包含 "/", "+" 以及 "#" 的字符串。订阅会话通过使用相同的 {ShareName} 表示共享同一个订阅,匹配该订阅的消息每次只会发布给其中一个会话

  • {filter} 即非共享订阅中的主题过滤器

通配符

1、通配符: +

单级通配符,可以用于topic的中间段也可以用于最后一段 比如: aaa/+/bbb aaa/+ 都是可以的,注意:aaa/+无法匹配 aaa后面必须要跟东西才行。

2、通配符: #

多级通配符,只能用于最后一段

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ZY.MQTT:

Package Downloads
ZY.PlateRecognition.MQTT

车牌识别摄像头MQTT协议

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 334 1/20/2026
1.0.4 146 1/20/2026
1.0.3 706 7/25/2025
1.0.2 554 7/25/2025
1.0.1 1,202 3/6/2024
1.0.0.3 372 12/21/2023
1.0.0.2 249 11/30/2023
1.0.0.1 223 9/26/2023