-
1. Re: How to pass a camel exchange property into CacheBasedMessageBodyReplacer processor
davsclaus Feb 14, 2017 4:13 AM (in response to stuelpm)The processor is created only once when Camel is starting up and creating the route model.
Therefore you cannot / should not do this. Instead you can get information from the exchange at runtime from the process(Exchange exhange) method, so just do
.process(new CacheBasedMessageBodyReplacer("cache://MyApplicationCache"))
And then in the process method you can get that information
public void process(Exchange exchange) {
Object counter = exchange.getProperty("xxx")
...
}
-
2. Re: How to pass a camel exchange property into CacheBasedMessageBodyReplacer processor
stuelpm Feb 15, 2017 1:36 PM (in response to davsclaus)Thanks Claus for your reply!
I understood that the processor is created only at once at startup.
The constructor of the CacheBasedMessageBodyReplacer processor, which is provided as part of camel-cache component, expects the cache name and the key as parameter.
So how can I use the approach that you are suggesting? Is there a way to wrap the provided processor into my own processor or something similar?
Thanks,
Markus
-
3. Re: How to pass a camel exchange property into CacheBasedMessageBodyReplacer processor
davsclaus Feb 15, 2017 3:41 PM (in response to stuelpm)You can create that processor from inside another processor.
But the processor code is not so good/dynamic as it creates the cache manager instance on each request and the key is not dynamic. So you can actually write a better processor yourself.
-
4. Re: How to pass a camel exchange property into CacheBasedMessageBodyReplacer processor
davsclaus Feb 15, 2017 4:02 PM (in response to davsclaus)So this commit made the processor better in the future. You could do something similar yourself
CAMEL-10838: camel-cache - Create a better body replacer processor · apache/camel@bdf4aaa · GitHub
You can then pass in the expression using ExpressionBuilder.exchangePropertyExpression("xxx")