Camel end vs endChoice - not the usual query

前端 未结 2 1302
栀梦
栀梦 2021-02-18 23:07

First, yes, I have searched and, yes, I have read the same Apache document every one points to. :-) I think there is a bit of confusion and I think I know an answer, so let me

2条回答
  •  心在旅途
    2021-02-18 23:32

    Coming late in the game, but might help.

    Nested choice definitions work just fine with Camel. Only your terminators are wrong:

    • .endChoice() --> to close a "when" predicate
    • .end() --> to close the entire "choice" block

    I know, the syntax is a bit confusing.

    So in your case:

    .choice()
        .when(X1)
            // do stuff
    
            .choice()
                .when(Y)
                    //do more stuff
                .endChoice() // close Y condition
    
            .end() // close inner choice block
    
        .endChoice() // close X1 condition
    
        .when(X2)
            // do other stuff
        .endChoice() // close X2 condition
    
        .otherwise()
            // default case
        .endChoice() // close default condition
    
    .end()
    

    In practice, you don't have to close all when predicates, only for multiple child routings. In my humble opinion, being super meticulous with the indentation helps a lot.

提交回复
热议问题