gpt4 book ai didi

java - 如何将 MessageGroupId 参数添加到消息中?

转载 作者:行者123 更新时间:2023-12-04 07:22:33 24 4
gpt4 key购买 nike

我正在尝试使用 JmsTemplate 将消息发送到 AwsSQS fifo 队列.
代码:

Message message = new Message().withBody("Hi");
jmsTemplate.convertAndSend(message);
当我运行上面的代码时,我收到错误
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

我试过添加 MessageGroupId像这样,但这也不起作用
Message message = new Message().withBody("Hi")
.withAttributes(Map.of("MessageGroupId", "1"));
jmsTemplate.convertAndSend(message);
有没有其他方法可以使用 JmsTemplate 将消息发送到 SQS fifo 队列?

最佳答案

来自 aws documentation ,您需要设置JMSXGroupID在标题或属性中

JMSXGroupID (required for FIFO queues, not allowed for standard queues)


另外,看看 key terms ,您可能还需要重复数据删除 ID。

关于java - 如何将 MessageGroupId 参数添加到消息中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68408192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com