简体   繁体   中英

Apache Camel route Splitter not returning original message

According to the Splitter documentation , in Camel 2.3 or newer the Splitter should return the original message. We are using 2.13.2, but after a split() the body seems to be that of the last split message (ie the behaviour described for Camel 2.2).

Our route is as follows:

    from(INPUT_SERVICE_ENDPOINT_URI)
            .wireTap(SAVE_COPY_OF_INPUT)
            .unmarshal(jaxbFormat)
            .process(createAuditRecord())
            .bean(webServiceValidator)
            .process(updateAuditRecord())
            .split(body())
                .choice()
                    .when(simple("${body.second.rejected}"))
                        .log(LoggingLevel.DEBUG, LOGGER_NAME, "Skipping import as it was rejected")
                    .otherwise()
                        .to(ExchangePattern.InOnly, IMPORT_QUEUE_ENDPOINT_URI)
                .endChoice()
            .end()
            .process(createWebServiceResponse())
            .marshal(jaxbFormat);

The idea is that a single web service request contains multiple items to be imported. The entire input message is validated (webServiceValidator) and the message body is transformed to a list of items by this validator. We then split the items so that they will be processed by the import queue individually.

The createWebServiceResponse processor assumes that the body of the message will be as it was before the split (ie a list of items), however it appears that the body only contains a single item (the last to be processed).

Is this behaviour correct? Is the the Splitter documentation wrong or have I misunderstood it? or have we done something wrong in our route definition?

I realise that I have not implemented an aggregation strategy, as in the other examples mentioned in the documentation, but I was hoping to avoid having to do this if I can just get a copy of the message as it was before the split.

This behaviour is caused because I didn't close my "choice" block properly. ie the route should look like this:

from(INPUT_SERVICE_ENDPOINT_URI)
        .wireTap(SAVE_COPY_OF_INPUT)
        .unmarshal(jaxbFormat)
        .process(createAuditRecord())
        .bean(webServiceValidator)
        .process(updateAuditRecord())
        .split(body())
            .choice()
                .when(simple("${body.second.rejected}"))
                    .log(LoggingLevel.DEBUG, LOGGER_NAME, "Skipping import as it was rejected")
                .otherwise()
                    .to(ExchangePattern.InOnly, IMPORT_QUEUE_ENDPOINT_URI)
                .endChoice()
            .end()
        .end()
        .process(createWebServiceResponse())
        .marshal(jaxbFormat);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM