Reputation: 708
public class AddingToCache extends RouteBuilder {
public void configure() {
from("jms:cacheTest")
.log("START")
.setHeader("CamelCacheOperation", constant("CamelCacheAdd"))
.setHeader("CamelCacheKey", constant("Custom_key"))
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody("${body.customerDetails.firstName}");
}
})
.log("starting ...")
.to("cache://cache1?maxElementsInMemory=1000&eternal=true")
.to("direct:next");
}
}
I'm trying to use camel cache for the first time and keep getting the error:
CamelCacheOperation header not specified in message
I've checked different sites including Camel's official website but can't find anything which points to how to solve this problem.
Upvotes: 1
Views: 305
Reputation: 55750
In the processor you should mutate the existing IN message, or otherwise if you use OUT then you need to copy over headers etc. See more details in this FAQ: http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
eg do
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("${body.customerDetails.firstName}");
}
And mind that this will set the body to a string, not the firstName of a POJO. For that to work you need to use the simple language, or get the body as the POJO and use Java code to call getCustomerDetails .. getFirstName etc. But that is another question.
Upvotes: 1