如何使用Apache骆驼向批处理消息发送批处理消息

时间:2020-07-12 16:39:39

标签: java apache-camel amazon-sqs

我在apache骆驼中有一个休息的api。我写了这样的代码,按照他们的文档,使用apache骆驼向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&region=us-east-1&operation=sendBatchMessage")
                    .endRest()

但这将返回java.lang.NullPointerException。这就是他们的文档中给出的方式。还有其他使用Apache骆驼将批处理消息发送到sqs的方法吗?

1 个答案:

答案 0 :(得分:0)

如文档中所述,您需要将iterable作为主体传递。这是一个集成测试: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

我不知道您从何处了解到有关发送批处理消息的方式。如果文档不正确,可以请您报告问题吗?谢谢。