in Dotnetcoresamples/Iotdotnetcoreconsumer/Program.cs [15:42]
static void Main(string[] args)
{
string iotEndpoint = "<<your-iot-endpoint>>";
int brokerPort = 8883;
Console.WriteLine("AWS IoT dotnetcore message consumer starting..");
var caCert = X509Certificate.CreateFromCertFile(Path.Join(AppContext.BaseDirectory, "AmazonRootCA1.crt"));
var clientCert = new X509Certificate2(Path.Join(AppContext.BaseDirectory, "certificate.cert.pfx"), "MyPassword1");
var client = new MqttClient(iotEndpoint, brokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
client.MqttMsgSubscribed += IotClient_MqttMsgSubscribed;
client.MqttMsgPublishReceived += IotClient_MqttMsgPublishReceived;
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
Console.WriteLine($"Connected to AWS IoT with client ID: {clientId}");
string topic = "Hello/World";
Console.WriteLine($"Subscribing to topic: {topic}");
client.Subscribe(new string[] { topic }, new byte[] {MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
// Keep the main thread alive for the event receivers to get invoked
KeepConsoleAppRunning(() => {
client.Disconnect();
Console.WriteLine("Disconnecting client..");
});
}