For this 2 options:
- One, let camel component move the file, or create a doneFileName so the file is marked as already processed.
- Use idempotentrepository, for this you should set noop=true in the camel component, and by default it will use a MemoryIdempotentRepository. If you need al alternate implementation, define which one to use, or create your own implementation and register in camelContext to use with #MyIdempotentRepo.
Look at the camel file2 component docs, as there is enough info there on how to set it up. http://camel.apache.org/file2.html
Hope it helps,
thanks for the reply. yes, i want to use FileIdempotentRespository. the filesystem i'm watching is mounted read only. therefore, i can't use .done files or move the files. the filesystem is owned by another system, but they let me mount their files for reading.
the examples for FileIdempotentRepository shows to use a spring configuration to define the bean and then to add it to the camel context. I don't understand how to do this with switchyard:
camel docs show:
<bean id="fileStore" class="org.apache.camel.processor.idempotent.FileIdempotentRepository"> <!-- the filename for the store --> <property name="fileStore" value="target/fileidempotent/.filestore.dat"/> <!-- the max filesize in bytes for the file. Camel will trunk and flush the cache if the file gets bigger --> <property name="maxFileStoreSize" value="512000"/> <!-- the number of elements in our store --> <property name="cacheSize" value="250"/> </bean>
my sy.xml is:
<sca:service name="CamelRouteTest" promote="CamelRoute/CamelRouteTest"> <sca:interface.java interface="com.example.switchyard.bar.CamelRouteTest"/> <file:binding.file name="file1"> <file:directory>/tmp</file:directory> <file:consume> <file:noop>true</file:noop> <file:include>.*txt</file:include> <file:idempotent>true</file:idempotent> </file:consume> </file:binding.file> </sca:service>
You can create a Bean in SwitchYard, extending the FileIdemtpotentRepository and add the @Named annotation, this will add it into the CamelContext. Then you can use #YourBean as a reference in the SwitchYard`s composite service binding for the idempotentRepository property.
Remember that every CDI Bean will get registered in the CamelContext.
Hope this helps.
thanks so much Jorge! that worked very nicely. I must say, I had several troubles getting it to work. Based on what I read, I only needed an @Named bean and not a switchyard service/bean. I tried that and was unsuccessful. Then, after I had one working example, I wanted to give better names to the classes and it just didn't work with a new class.
for anyone interested, i've updated my example listed above to show the implementation
Very glad it worked :-D
I was trying to see the updated example but not sure where. Should the example in your previous comment be updated? I don't seem to see it. It would be great to have it around for other's referenes.
Again, glad to help.
I did quickly review your implementation, and you're right, it should not require a service, but with @Named should suffice to add the CDI Bean into the CamelRegistry.
There might be an issue in the order of things being registered.
Would you mind opening a JIRA for this, given you have a sample app, or describe more your versions, so a JIRA can be created if it doesn't work.
In my case, I should need to reproduce it first to be sure that it doesn't work as expected, but since you've tried it, I'm pretty sure it would be much easier for you.
From the Switchyard docs:
SwitchYard integrates the CDI Bean Manager with the Camel Bean Registry to allow you to reference CDI Beans in your Camel routes. Any Java class annotated with @Named in your application will be available through Camel's Bean registry.
So either a bug in behavior, or in doc :-D
Thanks and cheers,
I've submitted the jira.
It turns out that after working with my example a bit, the CDI bean does work, it just needs to be explicitly named with @Named("BeanName")