Skip to content
Advertisement

SQS FIFO Using MessageGroupId to receive message

How do I use the messagegroupid parameter to only receive queue messages tagged with the id I need?

I’ve been trying to use the line below to retrieve but it will always receive all the queue messages from other group id as well.

List<Message> messages = sqs.receiveMessage(receiveMessageRequest.withAttributeNames("MessageGroupId")).getMessages();

What should be the correct way to do it?

Advertisement

Answer

The ReceiveMessageRequest is not used for filtering based on message attributes. If you look at the docs for ReceiveMessageRequest.html.withAttributeNames() it says:

A list of attributes that need to be returned along with each message.

In general, you can’t filter on the messages you get back from SQS. You can limit the number but you can’t say, for example, “give me all the messages that match this pattern”.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement