0

I have the following routing query defined in Azure IotHub: $body.messageType="Test"

And using Microsoft.Azure.Devices.Client" SDK Version="1.28.0"

Here is my very simple C# code.

            var device = DeviceClient.CreateFromConnectionString(DeviceConnectionString);
       
            await device.OpenAsync();

            var obj = new
            {
                messageType = "Test"
            };

            var telemetryJson = JsonConvert.SerializeObject(obj);

            var message = new Message(Encoding.UTF8.GetBytes(telemetryJson));

            // Set message body type and content encoding. 
            message.ContentEncoding = "utf-8";
            message.ContentType = "application/json";

            await device.SendEventAsync(message);

Message gets delivered to IotHub but routing is not applied! Any idea why?

Mori
  • 2,484
  • 5
  • 28
  • 45
  • the routing query string is OK. Could you post the screen snippet of the Route details? – Roman Kiss Sep 02 '20 at 11:33
  • 1
    also, for test purpose, add the *Device Telemetry Messages* routing (true) to the storage blob. You should see the message body in the json formatted text, such as **{ "messageType":"Test" }** – Roman Kiss Sep 02 '20 at 11:40
  • also IoT Hub emits diagnostic logs for Routes which might help – Helikaon Sep 02 '20 at 19:16

2 Answers2

0

Could you try it with single quotes like this $body.messageType='Test'?

Helikaon
  • 1,490
  • 13
  • 30
0

I noticed the IotHub resource's behavior was not normal at all. Different types of error messages started to appear like IotHub is not in an Active state whatsoever.

Deleting and recreating the resource resolved the issue.

Mori
  • 2,484
  • 5
  • 28
  • 45