拆分后从 Camel 路由获取原始消息

Getting original message from Camel route after splitting

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

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

我认为拆分器 returns 是原始消息?

这是我的路线:

    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...");

这是我在同一个 class:

中的异常处理程序
    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 解决

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