8 Replies Latest reply on Apr 15, 2015 7:10 PM by mlybarger

    configure switchyard file service to use FileIdempotentRepository

    mlybarger

      i'm writing a switchyard service that processes files in a folder. i only want to process new files that haven't been processed and it looks like the  FileIdempotentRepository is what is needed to store the name of processed files in a file itself.  this will work for my needs.

       

      git clone https://github.com/mlybarger/bar.git
      cd bar
      mvn jboss-as:deploy
      # app will log contents of *.txt files that show in /tmp
      echo message > /tmp/a.txt 
      echo message > /tmp/b.txt
      mvn jboss-as:deploy
      # existing files (a.txt && b.txt) should not be picked up.
      

       

      Help?

        • 1. Re: configure switchyard file service to use FileIdempotentRepository
          jorgemoralespou_2

          Hi Mark,

          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,

           

          Cheers,

          • 2. Re: configure switchyard file service to use FileIdempotentRepository
            mlybarger

            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>
            
            • 3. Re: configure switchyard file service to use FileIdempotentRepository
              jorgemoralespou_2

              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.

              • 4. Re: configure switchyard file service to use FileIdempotentRepository
                mlybarger

                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

                • 5. Re: configure switchyard file service to use FileIdempotentRepository
                  jorgemoralespou_2

                  Hi Mark,

                  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.

                  • 6. Re: configure switchyard file service to use FileIdempotentRepository
                    mlybarger

                    yes, the example is a simple switchyard application that is in github. you can get it using the link below.

                     

                    git clone https://github.com/mlybarger/bar.git


                    i've attached it for convenience.

                    • 7. Re: configure switchyard file service to use FileIdempotentRepository
                      jorgemoralespou_2

                      Hi Mark,

                      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,

                      • 8. Re: configure switchyard file service to use FileIdempotentRepository
                        mlybarger

                        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")

                         

                        [SWITCHYARD-2662] camel route using cdi bean requires explicit naming - JBoss Issue Tracker