Skip to main content

amqp.createmessage(body, properties)

Creates a new AMQP message in UTF-8 form




Name Type Description
body String The body of the message
properties Table Optional message properties as defined by the application


An amqpmessage object primed for transmission in UTF-8 form (‘AMQP VALUE’)


Important Note Agent AMQP functionality is now deprecated and will shortly become unsupported. Any attempt to interact with imp API amqp objects and methods on unregistered development devices or on production devices will generate a runtime error.

If you are using or intend to use Azure IoTHub, we recommend you make use of MQTT instead of AMQP. Please see our Azure IoT Hub integration for more information.

This method creates a new AMQP message. If the optional properties parameter is supplied, it will be used to construct the message. The keys which make up the properties table are application specific. For example, communicating with Microsoft’s Azure IoT Hub AMQP broker requires three properties keys and accompanying values for authentication: operation, type and name. The properties table keys must always be strings, and their values can only be of the following types: Integer, Float, Boolean or String. Passing in any other types is not currently supported, and an attempt will be made to convert them to a string.

Messages, once created, are immutable. If you need to update a message, you should create a new one with updated body and, optionally, properties data.

Note If you are sending JSON data, you may find that your AMQP broker does not accept JSON in the form of UTF-8 encoded strings. If this is the case, you should use the method amqp.createbinarymessage() to generate your message. This will cause the message to be transmitted in binary from (‘AMQP DATA’) rather than UTF-8.


The following snippet is part of a larger application which communicates with the Microsoft Azure IoT Hub. Here we create a global message which is transferred to the AMQP host. A simple log message informs the user when the message has been sent.


local properties = {};
properties.operation <- "put-token";
properties.type <- ""; <- HOST_NAME + "/devices/" + imp.configparams.deviceid;
local message = amqp.createmessage(sharedAccessSignature, properties);
local transfer = messageSender.createtransfer(message);
transfer.sendasync(function() {
  server.log("Message transferred");