Hcf Mqtt协议 通讯组件,封装基于MQTTnet的通讯实现
通过nuget引用 Hcf.Mqtt.Client 程序集
- Install-Package HcfNet.Mqtt.Client
添加 MqttClientPack 组件包
- services.AddPack<MqttClientPack>();//Mqtt作为客户端安装
- "Hcf": {
- "MqttClient": {
- "ClientId": "127.0.0.1",
- "Server": "127.0.0.1",
- "Port": 1883,
- "UserName": "admin",
- "Password": "password",
- "Timeout": 30, //秒
- "Interval": 10,
- "Topics": []
- }
- }
-
- IMqttClienter mqttClienter = provider.GetService<IMqttClienter>();
- mqttClienter.PublishAsync("test", "xiaoxi");
通过nuget引用 Hcf.Mqtt.Server 程序集
- Install-Package HcfNet.Mqtt.Server //本地应用程序
添加 MqttServerPack 组件包
- services.AddPack<MqttServerPack>();//Mqtt作为服务端安装
- "Hcf": {
- "MqttServer": {
- "Ip": null,
- "Port": 1883,
- "Timeout": 30,
- "UserName": null,
- "Password": null
- }
- }
通过nuget引用 Hcf.Mqtt.Server.AspNetCore 程序集
- Install-Package HcfNet.Mqtt.Server.AspNetCore
添加 AspNetCoreMqttServerPack 组件包
- services.AddPack<AspNetCoreMqttServerPack>();
- "Hcf": {
- "MqttServer": {
- "Ip": null,
- "Port": 1883,
- "Timeout": 30, //秒
- "UserName": null,
- "Password": null
- },
- "Kestrel": {
- "Port": 5000,
- "MaxRequestBufferSize": 33554432 //32M
- }
- }