THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block |
---|
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("ADD")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; |
...
Code Block |
---|
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("UPDATE")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; |
...
Code Block |
---|
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("DELETE")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; |
...
Code Block |
---|
RouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("DELETEALL")) .to("cache://TestCache1"); } }; |
Example 5: Notifying any changes registering in a Cache to Processors and other Producers
Code Block |
---|
Note: in this example the consumer is created first and then 3 routes send different message as Cache Producers RouteBuilder builder = new RouteBuilder() { public void configure() { from("cache://TestCache1") .process(new Processor() { public void process(Exchange exchange) throws Exception { String operation = (String) exchange.getIn().getHeader("CACHE_OPERATION"); String key = (String) exchange.getIn().getHeader("CACHE_KEY"); Object body .getHeader("CACHE_OPERATION"= exchange.getIn().getBody(); String// keyDo =something } }) (String) exchange.getIn()} }; |
Example 6: Using Processors to selectively replace payload with cache values
Code Block |
---|
RouteBuilder builder = new RouteBuilder() { public void configure() { //Message Body Replacer from("cache://TestCache1") .getHeaderfilter(header("CACHE_KEY").isEqualTo("greeting")) .process(new CacheBasedMessageBodyReplacer("cache://TestCache1","farewell")) .to("direct:next"); //Message Token replacer Object body = exchange.getIn(from("cache://TestCache1") .filter(header("CACHE_KEY").isEqualTo("quote")) .process(new CacheBasedTokenReplacer("cache://TestCache1","novel","#novel#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","author","#author#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","number","#number#")) .getBodyto("direct:next"); //Message XPath replacer from("cache:// Do something TestCache1"). .filter(header("CACHE_KEY").isEqualTo("XML_FRAGMENT")) .process(new CacheBasedXPathReplacer("cache://TestCache1","book1","/books/book1")) .process } (new CacheBasedXPathReplacer("cache://TestCache1","book2","/books/book2")) }).to("direct:next"); } }; |