Reputation: 11
[I am working with an AWS SQS FIFO queue and have sent several messages with different MessageGroupIds. However, when I try to retrieve the MessageGroupId from the received messages using the AWS SDK for Java, I am unable to get the value and it returns null.
Here is the code I’m using to receive the messages and attempt to extract the MessageGroupId:
private static final SqsClient sqsClient = SqsClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(DefaultCredentialsProvider.create())
.build();
private static final String queueUrl = "fifo_url";
ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder()
.queueUrl(queueUrl)
.maxNumberOfMessages(10)
.waitTimeSeconds(20)
.build();
ReceiveMessageResponse response = sqsClient.receiveMessage(receiveMessageRequest);
List<Message> messages = response.messages();
for (Message message : messages) {
Map<MessageSystemAttributeName, String> messageAttributes = message.attributes();
String messageGroupId = messageAttributes.get("MessageGroupId");
}
In another attempt, I tried accessing the MessageGroupId from the message attributes like this:
private static String getMessageGroupId(Message message) {
Map<String, MessageAttributeValue> attributes = message.messageAttributes();
if (attributes != null && attributes.containsKey("MessageGroupId")) {
return attributes.get("MessageGroupId").stringValue();
}
return "No Group ID";
}
](https://i.sstatic.net/yP8aBX0w.png)
What I have tried:
Upvotes: 1
Views: 35