Issue
I am trying to send message to AwsSQS fifo queue using JmsTemplate
.
Code:
Message message = new Message().withBody("Hi");
jmsTemplate.convertAndSend(message);
When I run the above code I'm getting the error
Caused by: com.amazonaws.services.sqs.model.AmazonSQSException: The request must contain the parameter MessageGroupId. (Service: AmazonSQS; Status Code: 400; Error Code: MissingParameter; Request ID: 94f6257b-0f2e-5e3d-9469-7c1066d45816; Proxy: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1819) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1403) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1372) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1145) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530) ~[aws-java-sdk-core-1.12.24.jar:na]
at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2271) ~[aws-java-sdk-sqs-1.12.24.jar:na]
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2238) ~[aws-java-sdk-sqs-1.12.24.jar:na]
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2227) ~[aws-java-sdk-sqs-1.12.24.jar:na]
at com.amazonaws.services.sqs.AmazonSQSClient.executeSendMessage(AmazonSQSClient.java:1817) ~[aws-java-sdk-sqs-1.12.24.jar:na]
at com.amazonaws.services.sqs.AmazonSQSClient.sendMessage(AmazonSQSClient.java:1786) ~[aws-java-sdk-sqs-1.12.24.jar:na]
at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.sendMessage(AmazonSQSMessagingClientWrapper.java:202) ~[amazon-sqs-java-messaging-lib-1.0.8.jar:na]
... 16 common frames omitted
I have tried adding MessageGroupId
like this but this is also not working
Message message = new Message().withBody("Hi")
.withAttributes(Map.of("MessageGroupId", "1"));
jmsTemplate.convertAndSend(message);
Is there any other way to send message to SQS fifo queue using JmsTemplate
?
Solution
From aws documentation, you need to set JMSXGroupID
in header or property
JMSXGroupID (required for FIFO queues, not allowed for standard queues)
Also, have a look at the key terms, you might also need a de-duplication id.
Answered By - mtk
Answer Checked By - Timothy Miller (JavaFixing Admin)