如何使用 apache camel 将批处理消息发送到 sqs 队列
How to send batch message to a sqs queue using apache camel
我在 apache camel 休息 api。我写了这样的代码,按照他们的文档使用 apache camel 向 sqs 发送批量消息。
.post("sqs-send-batch-message")
.route()
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
String message = "Hello World";
exchange.getIn().setBody(message);
}
})
.to("aws2-sqs://queueName?accessKey=insert&secretKey=insert®ion=us-east-1&operation=sendBatchMessage")
.endRest()
但这返回了 java.lang.NullPointerException
。这是他们文档中给出的方式。有没有其他方法可以使用 apache camel 向 sqs 发送批量消息?
如文档中所述,您需要将可迭代对象作为正文传递。这是一个集成测试:https://github.com/apache/camel/blob/master/components/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerBatchSendIntegrationTest.java
或者,您可以直接将 SendBatchRequest Pojo 作为正文传递:https://github.com/apache/camel/blob/master/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java#L107
这在文档中有说明:https://camel.apache.org/components/latest/aws2-sqs-component.html#_send_batch_message
我不知道你是从哪里了解到这种批量发送消息的方式的。如果文档某处不正确,您能否报告一个问题?谢谢
我在 apache camel 休息 api。我写了这样的代码,按照他们的文档使用 apache camel 向 sqs 发送批量消息。
.post("sqs-send-batch-message")
.route()
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
String message = "Hello World";
exchange.getIn().setBody(message);
}
})
.to("aws2-sqs://queueName?accessKey=insert&secretKey=insert®ion=us-east-1&operation=sendBatchMessage")
.endRest()
但这返回了 java.lang.NullPointerException
。这是他们文档中给出的方式。有没有其他方法可以使用 apache camel 向 sqs 发送批量消息?
如文档中所述,您需要将可迭代对象作为正文传递。这是一个集成测试:https://github.com/apache/camel/blob/master/components/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerBatchSendIntegrationTest.java
或者,您可以直接将 SendBatchRequest Pojo 作为正文传递:https://github.com/apache/camel/blob/master/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java#L107
这在文档中有说明:https://camel.apache.org/components/latest/aws2-sqs-component.html#_send_batch_message
我不知道你是从哪里了解到这种批量发送消息的方式的。如果文档某处不正确,您能否报告一个问题?谢谢