用jsonPath分割的Camel没有结果

时间:2018-05-25 07:14:09

标签: apache-camel

在我的camel路由中,我想将部分输出(json路径为$._attachments)发送到另一个端点。这有效。但是,在一些极端情况下,似乎有些json对象没有此元素。我猜这会导致CamelSplitSize为0,并尝试对其进行测试;但是,DefaultErrorHandler似乎会启动,而不是完成路由。我在这里做错了什么?

public class DiscoverAttachmentsFromCouchResponseRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception 
    {
        JsonPathExpression jsonPathExpression = new JsonPathExpression("$._attachments");

        Predicate no_attachments = header("CamelSplitSize").isEqualTo("0");

        errorHandler(
                deadLetterChannel("broker1:queue:dlq.jsonobject.queue")
                .maximumRedeliveries(3)
                );

        from("broker1:queue:input.jsonobject.queue")
        .routeId("DiscoverAttachmentsFromCouchResponseRoute")
        .threads(2)
        .split(jsonPathExpression)
            .marshal().json(JsonLibrary.Jackson,true)
            .to("broker1:queue:with.attachments.queue")
        .choice()
        .when(no_attachments)
            .log("No attachments found.")
            .to("broker1:queue:no.attachments.queue")
        .otherwise()
            .log("A grand total of '${header.CamelSplitSize}' attachments were found.")
        .endChoice();

    }

}

编辑某些时候答案太明显了......我正在寻找错误的地方。为什么我在问到它后几分钟似乎总能找到答案?我急需橡皮鸭。

我改变了路线;我不应该在拆分后处理问题,而应该在拆分之前完成:

    .choice()
        .when().jsonpath("$._attachments", true)
            .to("vm://withattach")
        .otherwise()
            .to("vm://withoutattach")
    .endChoice();

然后我只需要来自vm://*的两个新消费者并在那里做逻辑。这似乎有效。在jsonpath中,我可以跳过在JsonPathExpression中也不能在split()中执行的异常;

0 个答案:

没有答案
相关问题