Why am I getting SQS messages with different MessageGroupId's in a single boto3 receive_messages call?

0

I understand from the docs that if I am setting MessageGroupId when sending messages to a SQS FIFO, any and all messages returned in a single queue.receive_messages()boto3 call should have the same MessageGroupId. But I am getting messages with different MessageGroupId values in a single queue.receive_messages() call.

Here is how I am calling send_messages() using the python boto3 lib:

            client = boto3.resource(
                "sqs",
                region_name=utils.AWS_SQS_REGION,
                aws_access_key_id=utils.AWS_SQS_ACCESS_KEY,
                aws_secret_access_key=utils.AWS_SQS_SECRET_KEY,
            )
                queue = client.get_queue_by_name(QueueName=aws_queue_name)
                for chunk in chunked(queue_bulk_kwargs, 10):  # Amazon SQS batch size limit is 10
                    Entries = [
                        {
                            "Id": str(uuid.uuid4()),
                            "MessageBody": json.dumps(args, cls=EnhancedJSONEncoder),
                            "MessageGroupId": str(args["calsync_account_id"]),
                            "MessageDeduplicationId": str(uuid.uuid4()).replace("-", ""),
                        }
                        for args in chunk
                    ]
                    response = queue.send_messages(Entries=Entries)

Here is how I am calling receive_messages():

        client = boto3.resource(
            "sqs",
            region_name=utils.AWS_SQS_REGION,
            aws_access_key_id=utils.AWS_SQS_ACCESS_KEY,
            aws_secret_access_key=utils.AWS_SQS_SECRET_KEY,
        )
        self._queue = client.Queue(QueueURL)
        messages = self._queue.receive_messages(
            MaxNumberOfMessages=self.AWS_SQS_QUEUE_CHUNK_SIZE, AttributeNames=["MessageGroupId"]
        )

Have I misunderstood how MessageGroupId works? Or is there another way to send and/or receive messages to only receive messages from one MessageGroupId at a time? Otherwise I have to manage a local ordered message cache which is the same as implementing a local queue and defeats the purpose of using SQS in the first place.

Thanks!

asked 2 years ago1102 views
1 Answer
0

As per the documentation:

ReceiveMessage might return messages with multiple MessageGroupId values.

profile pictureAWS
EXPERT
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions