Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
262 stars 227 forks source link

No support for dt-subject on HTTP Transport #1141

Closed ymoreiratiti closed 1 year ago

ymoreiratiti commented 2 years ago

Context

Description of the issue

When using the HTTP transport layer, the message property "dt-subject" is transformed to "iothub-app-dt-subject". This makes the Azure Hub API ignore the subject and show the message as unmodeled data.

Code sample exhibiting the issue

const message = new Message(
          JSON.stringify({
            datetimeSignal,
            line,
            version: iotDataCollectorProperties.lastCollectFlightReports,
          }),
        );

        message.properties.add('dt-subject', 'logHistory');
        message.contentType = 'application/json';
        message.contentEncoding = 'utf-8';

        await azureIoTClientMqtt.sendEvent(message);

image


Analysing the code I found the code block where all message properties is added to the header with the prefix iothub-app https://github.com/Azure/azure-iot-sdk-node/blob/26695213809ff87e3e052c8f82de3be3a8afc066/device/transport/http/src/http.ts#L177


The same appear to be happening with sendEventBatch. Check this file: https://github.com/Azure/azure-iot-sdk-node/blob/26695213809ff87e3e052c8f82de3be3a8afc066/device/transport/http/src/http.ts#L278


I believe he should detect when the message property is dt-subject and ignore prefix, so the header should be only "dt-subject".

anthonyvercolano commented 2 years ago

Well, um, maybe. Since PnP is still in preview, it's questionable whether we should be special casing dt-subject.

If you look in some other later preview material, usually in helper samples, you would see this as $.sub

You would find that in 'c'. Note that 'c' ONLY supports MQTT. C sharp, much to my surprise, does seem to support what you want for HTTP.

So, why not utilize MQTT? You can use MQTT over websockets if you face firewall issues.

ymoreiratiti commented 2 years ago

In my scenario, I have a cronjob who downloads the log and sends it line by line. Currently, I'm using MQTT and doing an iteration for each file line, but I believe using the batch will be more network optimized.

anthonyvercolano commented 2 years ago

@ymoreiratiti I'm not understanding here.

What are your referring to when you say "batch"? How does "batch" interact with using HTTP?

ymoreiratiti commented 2 years ago

@anthonyvercolano for batch i'm refering to sendEventBatch.

You can send multiple messages with one request.

anthonyvercolano commented 1 year ago

Released