【问题标题】:Getting original message from Camel route after splitting拆分后从骆驼路线获取原始消息
【发布时间】:2020-09-17 04:55:12
【问题描述】:

我有一个骆驼路由,它从队列中批量读取消息,处理消息并继续将它们一一发送到 api 并等待 api 响应。

当引发 500 响应时,我在检索开始时收到的原始消息时遇到问题。

我以为拆分器会返回原始消息?

这是我的路线:

    from(gatewayRouteConfig.getInputQueueEndpoint())
            .process(process1)
            .process(process2)
            .setExchangePattern(ExchangePattern.InOnly)
            .choice()
            .when().jsonpath("Message", true)
            .setBody(MESSAGE_WRAPPER_EXTRACTOR)
            .end()
            .split().method(messageSplitter, "splitMessages")
            .log(INFO, "Received Message : ${body}")
            .process(process3)
            .process(validate)
            .process(identity)
            .process(requestProcessor) //where the exception is thrown and the original message that is used in the exception handler is picking up
            .process(someService::gatewayResponseTimeStop)
            .process(someService::endToEndResponseStop)
            .process(someService::markGatewayDeliveryAsSuccess)
            .log("Completed processing...");

这是我在同一个类中的异常处理程序:

    private void configureExceptionHandlers() {

        onException(ProviderException.class) //thrown when 500 error occurs
            .useOriginalMessage() //picks message in the form the process(requestProcessor) method recieves it instead of start of route
            .handled(true)
            .log(ERROR, LOGGER, EXCEPTION_MESSAGE_WITH_STACKTRACE)
            .to(DLQ);

【问题讨论】:

  • 您可能需要shareUnitOfWork 才能使用useOriginalMessage.split().method(messageSplitter, "splitMessages").shareUnitOfWork()
  • 是的,这正是我一直在想的,因为 split 方法有新的实体

标签: java spring apache-camel message-queue spring-camel


【解决方案1】:

通过添加shareUnitOfWork解决

.split().method(activityMessageSplitter, "splitActivityMessages").shareUnitOfWork()

【讨论】:

    猜你喜欢
    • 2013-12-04
    • 2017-08-04
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多