I'm using ehcache 3.0 and the latest version of Apache camel. I'd like to delete the element from cache after 120 seconds.
Following is the piece of code I'm using to achieve the same
<setHeader headerName="CamelCacheOperation" id="setCamelEhCacheOperation001">
<constant>CamelCacheAdd</constant>
</setHeader>
<setHeader headerName="CamelCacheTimeToLive" id="setCamelCacheTimeToLive001">
<simple resultType="java.lang.Integer">120</simple>
</setHeader>
<setHeader headerName="CamelCacheTimeToIdle" id="setCamelCacheTimeToIdle001">
<simple resultType="java.lang.Integer">120</simple>
</setHeader>
<setHeader headerName="CamelCacheEternal" id="setCamelCacheEternal001">
<simple resultType="java.lang.Integer">0</simple>
</setHeader>
<setHeader headerName="CamelEhcacheAction" id="setCamelEhCacheAction001">
<constant>PUT</constant>
</setHeader>
<setHeader headerName="CamelEhCacheKey" id="setCamelEhCacheAction001">
<simple resultType="java.lang.String">${property[cachekey]}</simple>
</setHeader>
<setHeader headerName="CamelEhcacheValue" id="setCamelEhCacheValue001">
<simple>${body}</simple>
</setHeader>
<to id="putValueToEhCache" uri="ehcache://cache1?keyType=java.lang.String&valueType=java.lang.String"/>
Even after the TTL duration the element is staying in cache. I've been using this as a reference : https://camel.apache.org/cache.html I've been stuck on this for a while now.
Thanks in advance.
CamelCacheTimeToLive is for the old camel-cache component, the new one, camel-ehcache does not handle such header.
To configure cache expiration you need to set-up a custom configuration as explained http://www.ehcache.org/documentation/3.7/expiry.html
Related
I have the following Camel Context.
<camelContext id="_camuatomicservicecontext" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_camuatomicserviceroute1">
<from id="_from1" uri="direct-vm:camuatomicservice">
<description>accepts vm messages directly </description>
</from>
<log id="_log1" message="Camu Atomic Service body = ${body}, header= ${header.uriPattern}"/>
<!-- <to id="_to1" uri="restlet:protocol:localhost:8189/"/> -->
<setHeader headerName="api.key" id="_setHeader1">
<constant>replace later with properties api.key Does not matter for this poc</constant>
</setHeader>
<setHeader headerName="CamelHttpPath" id="_setOutHeader1">
<el>${header.uriPattern}</el>
</setHeader>
<to id="_to1" pattern="InOut" uri="netty4-http:http:localhost:8189/path"/>
<log id="_log2" message="CamuAtomicService Response body ${body}"/>
</route>
</camelContext>
From the documentation I expect the CamelHttpPath header to override the endpoint configuration "/path" such that calling Facade Services can pass the header.uriPattern in and dynamically change the resource they want to access. The bundle worked fine until I added the setHeader for CamelHttpPath and now getting "Waiting for dependencies." I assume I need to install a feature, but Simple EL in other bundles on that server work already so not sure what feature I need to install.
Instead of I used and it worked fine. The choice was farther down in the options.
I am trying to write a simple sample :) on Apache-camel velocity. It is supposed to pick up a file and insert its content in a pre-written text (in .vm file). But it just puts the file name in the place. Here is my scripts.
blueprint.xml
<camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
</camelContext>
and here is my .vm file content
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${in}
Best regards
${headers.senderPersonalName}
instead of ${in}, I also tried ${body} which didnt work.
Try to convert the body to string after retrieving content from URI the file.
Might this work, Your route will be like this
<route id="_route1">
<from id="_from1" uri="file:work/velocityFileInput"/>
<convertBodyTo id="_convertBodyFileContent" type="java.lang.String"/>
<setHeader headerName="receiver" id="_setHeader1">
<simple>sir</simple>
</setHeader>
<setHeader headerName="senderName" id="_setHeader1">
<simple>Magfa co.</simple>
</setHeader>
<setHeader headerName="meetingAddress" id="_setHeader1">
<simple> Tehran , Iran</simple>
</setHeader>
<setHeader headerName="senderPersonalName" id="_setHeader1">
<simple>Ehsan Zangeneh</simple>
</setHeader>
<to id="_to1" uri="velocity:email.vm"/>
<log message="${body}"></log>
</route>
and here is your .vm file content
Hello dear ${headers.receiver},
This letter is sent from ${headers.senderName} to inform you that you are
invited to the meeting in the address of '${headers.meetingAddress}'.
The meeting is about
${body}
Best regards
${headers.senderPersonalName}
I'm writing one basic camel application using camel-spring.I'm able to send email but Im not able to send body and subject in it.I have tried several ways but only thing im getting in mail body is file contents.Please provide your inputs if you have any idea.
<route id="notification">
<from uri="file:///home?noop=true" />
<camel:choice>
<camel:when>
<camel:simple>
${file:name} contains '{{data}}'
</camel:simple>
<camel:setHeader headerName="from">
<simple>nikhil#from.com</simple>
</camel:setHeader>
<setHeader headerName="subject">
<constant>Hello subject</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<camel:setHeader headerName="body">
<constant>Test body</constant>
</camel:setHeader>
<camel:setBody>
<constant>Test camel set body</constant>
</camel:setBody>
<setBody>
<constant>Test set body</constant>
</setBody>
<camel:setOutHeader headerName="subject">
<simple>subject from outheader</simple>
</camel:setOutHeader>
<setHeader headerName="subject">
<constant>Status of check report extractor</constant>
</setHeader>
<camel:to uri="smtps://smtp.server.com:465?username=user#gmail.com&password=pass&to=receiver#yahoo.com&subject=${subject}"></camel:to>
</camel:when>
</camel:choice>
</route>
I have added all combinations that I have tried,but they are not workingThanks in advance.
Please, give a try to this route.
<route id="notification">
<from uri="file:///home?noop=true" />
<setHeader headerName="from">
<constant>nikhil#from.com</constant>
</setHeader>
<setHeader headerName="subject">
<constant>Hello subject</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<setBody>
<constant>Test camel set body</constant>
</setBody>
<to uri="smtps://smtp.server.com:465?username=user#gmail.com&password=pass&to=receiver#yahoo.com&from=${header.from}&subject=${header.subject}&contentType=${header.contentType}"/>
</route>
Then we can check the "when/simple" condition.
Note that all the stored headers in the route may be retrieved with ${header.X}.
I am trying to get the header or property which i set before calling hazelcast but i couldn't able to get the custom header which i set.
<route>
<from uri=""/>
<setHeader headerName="CamelHazelcastObjectId">
<constant>123</constant>
</setHeader>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<setHeader headerName="test">
<constant>test</constant>
</setHeader>
<setProperty propertyName="test">
<constant>test</constant>
</setProperty>
<to uri="hazelcast:map:testMap"/>
</route>
When i trying to retrieve my custom header or property couldn't able to get that
<route>
<from uri="hazelcast:map:testMap"/>
<log message = "printing:::: ${in.header.test} and ${property[test]}"/>
<to uri=""/>
Please help on this.
The camel-hazelcast component is only for storing the message body, not message headers.
I want to build a route something like
<route>
<from uri="servlet:///user?matchOnUriPrefix=true"/>
<to uri="direct:put"/>
</route>
<route>
<from uri="direct:put"/>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:foo"/>
</route>
ie everything that matches POST:/user/{cachename}/{key1} should take the key1 as key and place the payload under key:key1 to map:{cachename}.
Same thing for
GET:/user/{cachename}/{key1} should take the {key1} as key and retrieve the payload under key1 from map:{cachename}.
Any Help will be highly appreciated.
Thanks,
You should have a number of Camel headers available from the incoming servlet, such as:
CamelHttpMethod = GET
CamelHttpPath = /user/{cachename}/{key1}
You could use code or an expression language to extract the information from there, a very basic example would be:
<setHeader headerName="cachename">
<simple>${header.CamelHttpPath.split("/")[2]}</simple>
</setHeader>
<setHeader headerName="key1">
<simple>${header.CamelHttpPath.split("/")[3]}</simple>
</setHeader>