ZY.MQTT
1.0.5
dotnet add package ZY.MQTT --version 1.0.5
NuGet\Install-Package ZY.MQTT -Version 1.0.5
<PackageReference Include="ZY.MQTT" Version="1.0.5" />
<PackageVersion Include="ZY.MQTT" Version="1.0.5" />
<PackageReference Include="ZY.MQTT" />
paket add ZY.MQTT --version 1.0.5
#r "nuget: ZY.MQTT, 1.0.5"
#:package ZY.MQTT@1.0.5
#addin nuget:?package=ZY.MQTT&version=1.0.5
#tool nuget:?package=ZY.MQTT&version=1.0.5
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.2.0)
- MQTTnet (>= 4.3.1.873)
- Newtonsoft.Json (>= 12.0.2)
-
.NETStandard 2.1
- Microsoft.Extensions.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.2.0)
- MQTTnet (>= 4.3.1.873)
- Newtonsoft.Json (>= 12.0.2)
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.