My rule chain analytics is state-based, which means the calculation depends on the value of the previous data.
Let say the device generate data every second, so for 5 second there are 5 data from t=0 to t=4 (t=0, t=1, t=2, t=3, and t=4). In an ideal situation, first, the device will send the t=0 data and then Thingsboard will receive it. Next, the device will send the t=1 data and then Thingsboard will receive it. Next, the device will send the t=2 data and then Thingsboard will receive it. Therefore, Thingsboard will receive the data in chronological order based on the t value.
But due to the network issue, I faced a problem. Let say Thingsboard gets the t=3 data for now, but due to the network issue, the t=1 data just arrive exactly after the t=3 data. The t=1 should be sent and be received earlier than the t=3 data but it can happen because of a lost network connection. So the order of the data coming to the Thingsboard rule chain is broken.
So I think that I need to implement a queue to collect all the data first and sort it based on the timestamp before publishing it to Thingsboard. Let say the maximum delay between the device timestamp and the server timestamp is 15 minutes. So I need to make a queue for 15 minutes first before publishing it to thingsboard.
But how do I implement that queue? Or my idea is not the best solution?