OK, so instead of appending to the array in the loop, make your client.execute() there instead. That would mimic the message coming off the queue.
Ordering in subscriptions is not guaranteed. You can mitigate that with your own incrementing counter (a common tactic in pub-sub systems).