In continuation to the thread "How can Apache Camel be used to monitor file changes?"
I am using camel version 2.23.0, URL looks like
?noop=true&idempotentKey=${file:name}-${file:modified}
But the updated file is still not consumed by camel.
?noop=true&idempotentKey=$simple{file:name}-$simple{file:modified}
Related
I see a weird behavior with Apache Camel SFTP. Even after setting the delete=true attribute, it doesn't delete the file after receiving. I am using 3.0.0-M3 version of camel-ftp
Following is my SFTP configuration,
sftp://<<HOST_NAME>>:<<PORT>>/<<PATH>>?username=<<USERNAME>>" +
"&password=<<PASSWORD>>" +
"&preferredAuthentications=password" +
"&readLock=changed" +
"&readLockMinAge=30000" +
"&delay=20000" +
"&delete=true";
Now Camel is able to read the file, but it doesn't delete the file after reading. While going through the docs, it says
delete (consumer) -
If true, the file will be deleted after it is processed successfully.
How does camel define if it was processed successfully ? Do we need to set any exchange property for Camel to mark it processed successfully ?
After receiving the file all I am doing is pasing it to another route, like following,
from(endpointUri).to("direct:procesSftpFile");
Should I change it from direct to vm or seda?
Looks like nobody faced this issue and I somehow figured out the where this started happening.
The issue was not because of Camel sftp component, but it was with the piece of code I was calling.
Second part of my flow looks like this,
from("direct:procesSftpFile")
.log("...")
// logging and other regular processing
....
// sending to vm InOnly
.to("vm:queue1?exchangePattern=InOnly")
.. some more processing..
.to("vm:queue2?exchangePattern=InOnly")
So the issue was with calling those queue1 and queue2 in above snipet.
Commenting them, fixed it and sftp started deleting the files. For calling the VM, instead of to(), I used producerTemplate.asyncSend as workaround.
One thing I am still confused about is, if we are using InOnly exchange pattern, then why it is affecting the sftp behavior ? Probably I should ask this in a separate question.
Since a week I am dealing with the apache camel framework. I wanted to use it as a directory watcher and for new files it works fine. But if a file is deleted camel send no event so my application can be triggered to start the related action for deleted files like unregistering at a database or something else.
Therefore my question: is this possible to implement with apache camel or is it recommended to use the FileWatcher from the jdk?
I do not think it is possible at the moment but it looks interesting so it would be nice if you open a JIRA so we won't forget.
How can I access the "routeId" in Apache Camel 2.10?
I see that the property exists from camel 2.11.
From Simple Expression Langauge docs
${routeId}
String
Camel 2.11: Returns the id of the current route the Exchange is being routed.
Is there another easy hack available?
No, you would need to do a little piece of code to get the route id. You can check the source code of Camel 2.11 onwards to see how Camel does it in that function.
How do you set the TTL for a message when using Java DSL?
I have something like this:
...
from ("timer:something?delay=3000&period=15000")
...
.to("{{some.property}}")
.end()
...
I want to set a time to live on the message being sent.
I ended up setting the JMSExpiration header field of the messages being created similar to the following
.setHeader("JMSExpiration", constant(System.currentTimeMillis() + 1000))
We are using Apache ActiveMQ 5.7.
I assume TTL means Time to Live.
In Camel this is component specific how they deal with this. Some components support this, and others do not.
You should check the documentation for the component you use, what it supports.
If you use JMS component then it has the timeToLive option as documented: http://camel.apache.org/jms
And mind about the problem with "client and server clock's can be out of sync". There is some details on the Camel JMS page. Some message brokers has ways to sync the clocks, such as Apache ActiveMQ with its timestamp plugin: http://activemq.apache.org/timestampplugin.html
Can i download with camel a specific file list from a sftp server and then shutdown the service?
I know this should be a common question but i can't figure out how to do it without waiting the context stopping.
In some way, camel can ensure data integrity?
I guess you can do something like this using a direct route, pollEnrich and a template
from("direct:grabOneFile")
.pollEnrich("sftp://somewhere/blah/blah?fileName=foobar");
then from some java code somewhere, just grab a camel template and invoke the "direct:grabOneFile route.
String ret = template.requestBody("direct:grabOneFile","",String.class);
In this case, you don't have to worry about when to shut down the camel context with the chance of having multiple files etc.
Camel ftp component can only poll directories.
You can use a combination of maxMessagesPerPoll and fileName, like
from("ftp://.../xyz?maxMessagesPerPoll=x&fileName=y");
Also take a look at this.
This link has examples regarding shutdown.
Did you check this out at the bottom of the Camel FTP page.