拆分后从骆驼路线获取原始消息

时间:2020-05-29 15:07:07

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

我有一条骆驼路线,该路线从队列中批量读取消息,处理该消息,然后将它们逐一发送到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);

1 个答案:

答案 0 :(得分:0)

通过添加shareUnitOfWork来解决

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