Camel SQS unmarshal

时间:2018-03-28 12:57:37

标签: java apache-camel

我有非常简单的驼峰路由器,它使用SQS和base64解码:

 from("aws-sqs://test-camel-start?amazonSQSClient=#sqsClient&concurrentConsumers=2&maxMessagesPerPoll=1")
            .unmarshal()
            .base64()
            .process(new BaseProcessor())
            .to("aws-sqs://test-camel-success?amazonSQSClient=#sqsClient").end();

我的测试处理器:

 public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        String header = (String) exchange.getIn().getHeader("CamelAwsSqsMessageId");
        String message = exchange.getIn().getBody(String.class);
        MDC.put("message-id", header);
        Thread.sleep(5 * 1000);
        LOG.info("Async ping");
        LOG.info(message);
    } catch (Throwable e) {
        LOG.error(e.getMessage(), e);
        exchange.setException(e);
    }
    callback.done(false);
    return false;
}

所以我有下一个情况: 1)Camel成功读取来自" test-camel-start"队列 2)BaseProcessor成功处理消息 3)在重试传递消息到" test-camel-success"

时失败了

我收到了下一个日志记录:

  

637435 [Camel(HomeCamelSQS)线程#2 - aws-sqs:// test-camel-start]错误oacprocessor.DefaultErrorHandler cr.id = 18b85e94-bc2f-44dd-baef-4bcd4fb79e0c - 交付失败(MessageId:在ExchangeId上的ID-DESKTOP-5SBC4FA-1522239559145-0-6:ID-DESKTOP-5SBC4FA-1522239559145-0-5)。交付尝试后用尽:1抓住:com.amazonaws.services.sqs.model.AmazonSQSException:请求必须包含参数MessageBody。 (服务:AmazonSQS;状态代码:400;错误代码:MissingParameter;请求ID:85604fc2-0724-5d16-af6b-1cf78a24e8b0)

消息历史记录

RouteId ProcessorId处理器已用完(ms) [route1] [route1] [aws-sqs:// test-camel-start?amazonSQSClient =%23sqsClient& concurrentConsumers = 2&] [7591] [route1] [unmarshal1] [unmarshal [org.apache.camel.model.dataformat.Base64DataFormat@237080aa]] [1] [route1] [process1] [Processor @ 0x5007bde9] [7417] [route1] [to1] [aws-sqs:// test-camel-success?amazonSQSClient =#sqsClient] [172]

堆栈跟踪

com.amazonaws.services.sqs.model.AmazonSQSException:请求必须包含参数MessageBody。 (服务:AmazonSQS;状态代码:400;错误代码:MissingParameter;请求ID:85604fc2-0724-5d16-af6b-1cf78a24e8b0)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1638)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeOneRequest(AmazonHttpClient.java:1303)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeHelper(AmazonHttpClient.java:1055)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.doExecute(AmazonHttpClient.java:743)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.execute(AmazonHttpClient.java:699)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.access $ 500(AmazonHttpClient.java:667)     在com.amazonaws.http.AmazonHttpClient $ RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)     在com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)     在com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2013)     在com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:1989)     在com.amazonaws.services.sqs.AmazonSQSClient.executeSendMessage(AmazonSQSClient.java:1594)     在com.amazonaws.services.sqs.AmazonSQSClient.sendMessage(AmazonSQSClient.java:1571)     在org.apache.camel.component.aws.sqs.SqsProducer.process(SqsProducer.java:62)     at org.apache.camel.util.AsyncProcessorConverterHelper $ ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)     在org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)     在org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)     在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)     在org.apache.camel.processor.Pipeline.process(Pipeline.java:138)     在org.apache.camel.processor.Pipeline.access $ 100(Pipeline.java:43)     在org.apache.camel.processor.Pipeline $ 1.done(Pipeline.java:157)     at org.apache.camel.processor.CamelInternalProcessor $ InternalCallback.done(CamelInternalProcessor.java:262)     at org.apache.camel.processor.RedeliveryErrorHandler $ 2.done(RedeliveryErrorHandler.java:560)     在com.home.camel_poligon.BaseProcessor.process(BaseProcessor.java:35)     在org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:110)     在org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)     在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)     在org.apache.camel.processor.Pipeline.process(Pipeline.java:138)     在org.apache.camel.processor.Pipeline.process(Pipeline.java:101)     在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)     在org.apache.camel.component.aws.sqs.SqsConsumer.processBatch(SqsConsumer.java:206)     在org.apache.camel.component.aws.sqs.SqsConsumer.poll(SqsConsumer.java:111)     在org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)     在org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)     at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)     at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)     at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 301(ScheduledThreadPoolExecutor.java:180)     at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

Log表示"请求必须包含参数MessageBody"。

而且我不知道为什么这个消息体不存在。

1 个答案:

答案 0 :(得分:2)

请参阅此常见问题解答:http://camel.apache.org/why-is-my-message-body-empty.html

在处理器中,将邮件正文转换为记录的字符串。由于消息正文是基于流的(例如base64的输出),它会将正文读取到流的末尾,然后消息将看到为空。

您可以启用流缓存,也不要在处理器中执行此手动记录。