Skip to main content

amqpmessage.body()

Returns the target AMQP message’s body content

Availability

Agent

Returns

Various — see below

Description

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 returns the body content of the target message. The method will attempt to map AMQP data types to their Squirrel equivalents, but this is not always possible. The AMQP data types which can be converted are as follows:

AMQP Body Type AMQP Body Type Notes Squirrel Data Type
amqp_NULL_TYPE The null type, contains no data Null
amqp_BOOLEAN Boolean true or false Bool
amqp_UBYTE Unsigned 8-bit integer Integer
amqp_BYTE Signed 8-bit integer Integer
amqp_USHORT Unsigned 16-bit integer Integer
amqp_SHORT Signed 16-bit integer Integer
amqp_UINT Unsigned 32-bit integer Integer
amqp_INT Signed 32-bit integer Integer
amqp_ULONG Unsigned 64-bit integer Integer
amqp_LONG Signed 64-bit integer Integer
amqp_FLOAT 32-bit binary floating point Float
amqp_DOUBLE 64-bit binary floating point Float
amqp_BINARY Variable length sequence of bytes Blob
amqp_STRING Variable length UTF8-encoded string String
amqp_SYMBOL Variable length encoded string String
amqp_ARRAY A sequence of values of the same type Array
amqp_LIST A sequence of values, may be of mixed types Array
amqp_MAP A sequence of key:value pairs, may be of mixed types Table

 
Note 32-bit unsigned integers and all 64-bit values will overflow when converted to Squirrel signed 32-bit integers or floats. This will happen without warning.

The following AMQP body types are not currently supported, and amqpmessage.body() will return a warning string of this kind: "Unhandled message body type <THE_TYPE>":

AMQP Body Type AMQP Body Type Notes Squirrel Data Type
amqp_CHAR 2-bit unicode character None
amqp_TIMESTAMP Signed 64-bit milliseconds since the epoch None
amqp_DECIMAL32 32-bit decimal floating point None
amqp_DECIMAL64 64-bit decimal floating point None
amqp_DECIMAL128 128-bit decimal floating point None
amqp_UUID 16-byte UUID None
amqp_DESCRIBED A descriptor and a value None

 
The compound AMQP body types (amqp_ARRAY, amqp_LIST and amqp_MAP) can be nested, and therefore amqpmessage.body() can return either a Squirrel array or a Squirrel table that contains a series of nested arrays and/or tables, plus other data types as appropriate. If unsupported types appear in an amqp_ARRAY, amqp_LIST or amqp_MAP then they will not appear in the corresponding Squirrel table or array. The unsupported entities are omitted — they are not replaced with a warning strings like the one shown above.

In Squirrel, null is not a valid table key, and therefore if the AMQP message contains an amqp_MAP in which an amqp_NULL_TYPE is used as a key, then this slot (ie. both key and value) will be omitted from the Squirrel table returned by amqpmessage.body().

This decoding applies only to incoming messages — the body of an outgoing message is always generated with string data. You can use JSON that has been encoded to send tables and other data structures as strings, but be aware that the AMQP broker you are targeting may expect to receive such structures as native AMQP types, such as amqp_ARRAY or AMQP_MAP, and simple data types as, for example, amqp_INT, amqp_BOOLEAN and amqp_FLOAT.

Note This method cannot be used to update a message; the returned value should be considered read only.