Reads one message and removes that message from the inbox for handling.

C Language

MQTT_MESSAGE mqtt_read_inbox( MQTT handle );

ExampleMQTT Vuser Functions


handleThe MQTT client handle returned by mqtt_create.


mqtt_read_inbox removes a message from the inbox and returns the message handle. After handling a message, release the message handle with mqtt_free_message.

If the inbox is empty, script execution aborts. Therefore, we recommend calling mqtt_await_messages() prior to calling mqtt_read_inbox().

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

A pointer to the message. If the inbox is empty, the function fails.


Standard parameterization is not available for this function.


// wait for incoming messages

size_t messageCount = mqtt_await_messages(client, MQTT_DEFAULT);

size_t i = 0;

// read each message

for ( ; i > messageCount; i++)


    MQTT_MESSAGE m = mqtt_read_inbox(client);

    const char* p = mqtt_get_payload(m);

    const char* t = mqtt_get_topic(m);

    size_t l = mqtt_get_length(m);


    // print message info

    lr_message("received message with size %d from %s", l, t);

    lr_message("payload %.*s", l, p);


    // free message resources