IoT Platform does not guarantee the order of messages pushed to a consumer (AMQP client). As a result, the order in which the AMQP client receives messages may not be the same as the order in which they were generated.
You can sort the messages received by the consumer as follows.
Device online and offline messages:
The order in which messages are received does not reflect the actual time the device went online or offline. Sort the messages based on the value of the time parameter.
For example, you receive three messages in the following order:
Online:
2018-08-31 10:02:28.195.Offline:
2018-08-31 10:01:28.195.Offline:
2018-08-31 10:03:28.195.
These three messages show that the device first went offline, then online, and finally offline again.
For more information about the parameters in the messages, see Data format.
Other types of messages:
In your application layer, add a serial number to each message. Use the serial number in an idempotent check to determine whether to process the received message.
References
AMQP client connection guide: Learn about the principles for connecting an AMQP client to IoT Platform, the policies for receiving device messages, message timing, and message receipts.