MQTTnet TLS连接

时间:2018-10-10 21:16:24

标签: c# .net xamarin mqtt aws-iot

经过一番研究,我终于得到了一段有效的代码,可以将MQTT消息发送到测试蚊子到MQTT服务器

body {
    >div {
        &:nth-of-type(n {
            &+2) {
                background: red;
            }
            &+4) {
                background: blue;
            }
        }
    }
}

下一步是订阅并发布带有TLS的AWS IoT上的主题。

我知道我必须使用(在MqttClientOptionsBuilder中)

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();

但是我不确定如何指定用于进行身份验证的证书

任何帮助将不胜感激

0 个答案:

没有答案