繁体   English   中英

如何使用 apache camel 将批处理消息发送到 sqs 队列

[英]How to send batch message to a sqs queue using apache camel

我在 apache 骆驼中有一个 rest 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&region=us-east-1&operation=sendBatchMessage")
                    .endRest()

但这是返回java.lang.NullPointerException 这是他们在文档中给出的方式。 还有其他方法可以使用 apache 骆驼向 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

我不知道你在哪里读到了这种发送批量消息的方式。 如果文档不正确,您能否报告问题? 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM