c# - MQTTnet TLS 连接
问题描述
经过一番研究,我终于得到了一段工作代码,可以将 MQTT 消息发送到测试 mosquitto MQTT 服务器
var mqttClient = factory.CreateMqttClient();
var options = new MqttClientOptionsBuilder()
.WithTcpServer("test.mosquitto.org", 1883)
.WithClientId("client123")
.Build();
await mqttClient.ConnectAsync(options);
Main account = new Account
{
Email = "test@example.com",
Active = true,
CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
Roles = new List<string>
{
"User",
"Admin"
}
};
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
var message = new MqttApplicationMessageBuilder()
.WithTopic("MyTopic")
.WithPayload(json)
.WithExactlyOnceQoS()
.WithRetainFlag()
.Build();
await mqttClient.PublishAsync(message);
Console.WriteLine("press return to carry on");
Console.ReadLine();
我的下一步是使用 TLS 订阅和发布到 AWS IoT 上的主题。
我知道我必须使用(在 MqttClientOptionsBuilder 中)
.WithTls()
但我不确定如何指定使用哪个证书进行身份验证
任何帮助,将不胜感激
解决方案
推荐阅读
- r - 如何更改 ggplot 中的标题以获取一系列情节?
- node.js - Node.js 托管:低带宽,高 CPU
- mongodb - 如何与现代 Mongo scala 驱动程序一起运行传统的 Mongo Casbah 驱动程序
- azure - 将组添加到 ADO 中的所有服务连接
- typescript - Next.js、Styled-components 和 Yandex Metrica 会话重放
- node.js - 将 socket.io 升级到 v3 后出现 express-session 问题
- merge - 使用 Spacy 的模型“en_core_web_md”时,合并跨度非常慢
- python - 在python相同长度的循环中组合两个列表
- sql - 如何在oracle plsql中对clob进行子串化
- javascript - 在 nuxt.js 身份验证中,用户始终重定向到刷新时登录