Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Transport Obj on Promises #626

Closed
YoDaMa opened this issue Sep 13, 2019 · 2 comments
Closed

Nested Transport Obj on Promises #626

YoDaMa opened this issue Sep 13, 2019 · 2 comments
Assignees
Labels

Comments

@YoDaMa
Copy link
Contributor

YoDaMa commented Sep 13, 2019

per APerrine's notes:

To repro

require('dotenv').config()
const { Mqtt } = require('azure-iot-device-mqtt');
const { Client, Message } = require('azure-iot-device');

/* 
My least important question, but interesting...
why does the wrapping go transportObj : MessagEnqueued : transportObj??
(havent really investigated... maybe take out)
*/


const startMessageInterval = (client, messageDelay=3000) => setInterval( async() => {
    const asteroid = { size : Math.random()*100, timeTillImpact : Math.random()*100 } //leaving units to users imagination
    const msg = new Message( JSON.stringify(asteroid) )

    msg.properties.add('IMPACT_EMERGENCY', asteroid.timeTillImpact < 50 && asteroid.size > 50 ? 'true' : 'false')
    const transportObj = await client.sendEvent(msg).catch( err => console.error('Error sending message: ', err) )

    console.log(transportObj)

}, messageDelay)


const run = async() => {
    try {
        //create a client using the device connection string and the mqtt protocol
        const client = Client.fromConnectionString(process.env.DEVICE_CONN_STRING, Mqtt)
        const sendMessageInterval = startMessageInterval(client)


    } catch (err) {
        console.error('Error: ', err)
    }
}


run()
@YoDaMa
Copy link
Contributor Author

YoDaMa commented Sep 13, 2019

From my quick repro, this is the structure we get when setting a break point at console.log(transportObj):

MessageEnqueued
|---TransportObj 
      |---TransportObj

When I set a breakpoint internall in mqtt.ts:

> MessageEnqueued {transportObj: Object}
[[StableObjectId]]:7
> transportObj:Object {cmd: "publish", topic: "devices/beta/messages/events/IMPACT_EMERGENCY=fals…", payload: "{"size":19.24501545677899,"timeTillImpact":90.1477",}
[[StableObjectId]]:9
cmd:"publish"
dup:false
messageId:8386
payload:"{"size":19.24501545677899,"timeTillImpact":90.14774673121259}"
qos:1
retain:false
topic:"devices/beta/messages/events/IMPACT_EMERGENCY=false"

Which is correct. I will repro without promises to see if it is an issue with our promise code.

@az-iot-builder-01
Copy link
Collaborator

@YoDaMa, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants