Messages route to storage

AshokPeddakotla-MSFT 27,296 Reputation points
2020-05-14T17:48:47.2+00:00

Starting with IoT Hub for a small project and I'm stuck for 1 day in the following issue:

  • I've created the IoT Hub and one device
  • I've created the route to a storage container (JSON settings not AVRO)
  • I'm sending messages successfully, viewing them in Azure portal, Device explorer..., json messages like {temperature:50}

But when i'm viewing the blob data all the time I'm seeing something like:

{"EnqueuedTimeUtc":"2020-04-05T08:33:42.7200000Z","Properties":{"temperatureAlert":"false"},"SystemProperties":{"connectionDeviceId":"ESP1","connectionAuthMethod":"\"scope\":\"hub\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}","connectionDeviceGenerationId":"637137426272917278","enqueuedTime":"2020-04-05T08:33:42.7200000Z"},"Body":"eyJtZXNzYWdlSWQiOjAsInRlbXBlcmF0dXJlIjoyNCwiaHVtaWRpdHkiOjY0fQ=="} 

meaning the Body is something not recognizable and is the same for every message.

What could be the issue.

[Note: As we migrate from MSDN, this question has been posted by an Azure Cloud Engineer as a frequently asked question] Source: MSDN

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,115 questions
0 comments No comments
{count} vote

Accepted answer
  1. QuantumCache 20,031 Reputation points
    2020-05-14T17:59:50.007+00:00

    The data can be written to blob storage in either the Apache Avro format, which is the default, or JSON (preview).

    In order for IoT Hub to know whether the message can be routed based on its body contents, the message must contain specific headers which describe the content and encoding of its body.

    In particular, messages must have both these headers for routing on message body to work:

    Content type of "application/json" Content encoding must match one of: "utf-8" "utf-16" "utf-32"

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

    contentType="application/json" 

    contentEncoding=" UTF-8"

    if yes, then the body should be in the json formatted text:

    {"messageId":0,"temperature":24,"humidity":64}
    

    For more details, refer Message routing query based on message properties

    Also, note that the capability to encode JSON format is in preview in all regions in which IoT Hub is available, except East US, West US and West Europe. The encoding format can be only set at the time the blob storage endpoint is configured. The format cannot be changed for an endpoint that has already been set up. When using JSON encoding, you must set the contentType to JSON and the contentEncoding to UTF-8 in the message system properties.

    For more detailed information about using a blob storage endpoint, please see guidance on routing to storage.

    Source: MSDN

    0 comments No comments

0 additional answers

Sort by: Most helpful