I'm using boto3 client in python. I'm pushing messages to sqs but receive them in the wrong order. I can see that their sent time is correct.
The queue is created like that:
boto_session = boto3.Session(region_name=..,aws_access_key_id=.., aws_secret_access_key=...)
sqs_client = boto_session.resource('sqs', endpoint_url=endpoint_url)
sqs_client.create_queue(QueueName=...)
The code to push messages:
boto_session = boto3.Session(region_name=..,aws_access_key_id=..,aws_secret_access_key=...)
sqs_client = boto_session.resource('sqs', endpoint_url=endpoint_url)
queue = sqs_client.get_queue_by_name(QueueName=stream_name)
i = 0
while i < 10:
print 'b ' + str(i)
queue.send_message(MessageBody=raw_data.push(json.dumps(dict(id=i)))
sleep(2)
i += 1
And code for polling messages:
sqs_resource = boto_session.resource('sqs', endpoint_url=endpoint_url)
queue = sqs_resource.get_queue_by_name(QueueName=queue_name)
while True:
messages = queue.receive_messages(MaxNumberOfMessages=1,VisibilityTimeout=10,WaitTimeSeconds=5)
for m in messages:
print m.data
queue.delete_messages(
Entries=[
{
'Id': m.message_id,
'ReceiptHandle': m.receipt_handle
}
]
)
I ran the create queue code, then I pushed messages, then ran a process to consume the messages as shown.
I clearly see the messages are randomly ordered.
Is there a solution for this in sqs? or should I replace the queue?