简体   繁体   中英

How can we access to original input message after unmarshal in apache camel

I am getting an input json string from a queue to my camel route, I need to unmarshal it to get a java object. After unmarshal I can't access my original message via Exchange object in process. If anyone faced the same issue and found solution, could you please answer this.

I tried to unmarshal a json string to java object from incoming camel route. I wan to get access to original input message after unmarshal.

You can store the original body to an exchange property. Marshal by default replaces the message body but you can use exchange properties to store values for later use in the route.

from("jms:queue:example")
    .routeId("receiveExampleMessage")
    .convertBodyTo(String.class)
    .setProperty("originalBody", body())
    .unmarshal(exampleDataFormat)
    // Usage:
    // Log original body
    .log("original body ${exchangeProperty.originalBody}")
    // Use exchange property with plain java
    .process(ex -> {
        String originalBody = ex.getProperty("originalBody", 
            String.class);
    })
    // Set property value back to body
    .setBody().exchangeProperty("originalBody")
;

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