Camel - Split()和doCatch(....)不起作用

时间:2012-07-26 11:36:50

标签: apache-camel

我正在尝试构建一个尝试验证xml的路由,如果一切正确,则必须拆分此文件,否则抛出异常并且必须执行其他操作。所以我做了以下事情:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("validator:classpath:"+validator)
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();

但它没有编译(如果我不使用拆分然后它编译并工作),错误是:

The method doCatch(Class<ValidationException>) is undefined for the type ExpressionNode

所以我尝试了以下

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("direct:validate")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();

    from("direct:validate")
        .to("validator:classpath:"+validator)
        .to("direct:split_message");

    from("direct:split_message")
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text");

这次我得到重复端点的错误

 org.apache.camel.FailedToStartRouteException: Failed to start route route312 because of Multiple consumers for the same endpoint is not allowed: Endpoint[direct://validate]

你对如何解决这个问题有任何想法吗?

2 个答案:

答案 0 :(得分:6)

为了从split()块(或选择或其他嵌套类型)返回doTry()块,您需要使用endDoTry()。与其名称相反,此方法将结束嵌套的拆分块并返回到doTry()DSL。

我会使用您发布的第一条路线进行这些更改:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("validator:classpath:"+validator)
        .split(xPathMessageTypeSplit)
            .to("jms:"+queue+"?jmsMessageType=Text")
        .endDoTry()
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
            .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
        .endDoTry()
    .end();

答案 1 :(得分:1)

你的第二次尝试似乎很好。您获得的错误是由以from("direct:validate")开头的两条路线引起的 您的应用程序中是否有其他路由正在使用相同的端点?

编辑:尝试以不同的方式命名,可能已经存在验证(在您的应用中或在骆驼内)