Beispiel #1
0
        static async Task Run()
        {
            var mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);

            ITransportSettings[] settings = { mqttSetting };

            // Open a connection to the Edge runtime
            var ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);

            await ioTHubModuleClient.OpenAsync();

            Console.WriteLine("IoT Hub module client initialized.");

            var moduleTwin = await ioTHubModuleClient.GetTwinAsync();

            await ioTHubModuleClient.SetDesiredPropertyUpdateCallbackAsync((props, ctx) =>
            {
                Console.WriteLine("Handling update of desired properties is not yet implemented!");
                return(Task.CompletedTask);
            }, null);

            httpClient      = new HttpClient();
            rabbitMqManager = new RabbitMQManager(httpClient, new RabbitMQManagerInstrumentation());

            try
            {
                await rabbitMqManager.ApplyConfigAsync(moduleTwin);
                await UpdateReportedProperties(ioTHubModuleClient, OperationStatus.OK);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                await UpdateReportedProperties(ioTHubModuleClient, OperationStatus.Error);
            }
        }
        static async Task Run()
        {
            var mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);

            ITransportSettings[] settings = { mqttSetting };

            // Open a connection to the Edge runtime
            var ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);

            await ioTHubModuleClient.OpenAsync();

            Console.WriteLine("IoT Hub module client initialized.");

            httpClient      = new HttpClient();
            rabbitMqManager = new RabbitMQManager(httpClient, new RabbitMQManagerInstrumentation());

            await ioTHubModuleClient.SetDesiredPropertyUpdateCallbackAsync(async (props, ctx) =>
            {
                Console.WriteLine("Handling desired properties update!");
                await ApplyConfigAsync(ioTHubModuleClient);
            }, null);

            await ApplyConfigAsync(ioTHubModuleClient);
        }