Announcement Announcement Module
No announcement yet.
New to Spring Integration - Need help with Poller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • New to Spring Integration - Need help with Poller

    Hi Guys,
    I am new to spring/spring integration and I am trying to develop a poller that will poll a folder and (for now) just continously list all the files in the folder. I have the following in my config.xml 
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    <si:channel id="input">
            <si:queue capacity="100"/>
    <file:inbound-channel-adapter id ="fileinput" directory="/tmp" channel="input">
        <si:interval-trigger interval="1"/>
    <si:gateway id="readfile" service-interface="folderpoller.readFiles" default-request-channel="input"/>
    <bean id="readFileNames" class="folderpoller.readFileNames"
    and I have the following in my main.
        ApplicationContext context = new ClassPathXmlApplicationContext("folderPoller/config.xml");
         PollableChannel channel = (PollableChannel) context.getBean("input");
            Message<?> recv = channel.receive();
    I need to find a way to test this to make sure it is polling, currently I think it is only doing the pull once and not polling the folder over and over. On the INFO line I only get the following once for each file. I assume that if it is polling correctly it should show this each time it polls? Am I correct? If not can anyone spot a reason why this is not polling and only running once? There is a good chance that there is a fundamental flaw in my code, as I have mentioned before this is my first time using spring integration (and spring for that matter) so i am quite new to the whole thing.
    INFO: Created message: [[Payload=\tmp\Copy of test.txt]
    The bean that it points to (readFileNames) just reads the files from the directory.

    Thanks in advance for any help that I get. If i am not explaining something clearly, please let me know and i will try and explain again.

  • #2
    The default behavior for the file polling is to only accept each file once while the app is running. Do you want to re-read the same file repeatedly?

    Also, your polling interval is 1 millisecond. Most likely you want that to be a bigger number (e.g. interval="1000" for 1 second).


    • #3
      Hi Mark thanks for the reply. That actually makes sense. I added another file and it picks it up on the fly. Thanks (I think I was being quite a noob there, I apologize).

      I was playing with the timer, so it was 1 millisecond when i copy pasted my code. Have been using 1000, but going to configure it to 5000 later on.

      Thanks again. I see now that I get another INFO: message on the console for the new file. Is there anyway I can notify a thread the second the poller picks up something (i.e. in this case spots a new file in the folder)?


      • #4
        For immediate notification, you can remove the 'queue' sub-element from your 'input' channel. Then, connect something to that channel (e.g. a "service-activator" element). It will actually occur in the same thread that read the File by default. You can either configure the "task-executor" reference on that "poller" element to manage a thread pool there, or you can use a task-executor for the dispatching of the message itself. What version of Spring Integration are you using?


        • #5
          Using 1.0.3 (actually followed this guide of yours It was very helpful. I will try using a task-excutor and a service activator when I get a chance a little later.

          Is there any way to customize the file poller to notify when a file is modified (currently it only seems to notify on a new file)?

          Thanks again.


          • #6
            So I added a service activator and task executor (attached to my poller).

            My Service activator looks like this:

            <si:service-activator input-channel="input" ref="processFile" method="fileProcessor" output-channel="output" >
            Everytime it polls I get a message back on the command line (INFO: message). I want to read this message. So I use the event handler to print the messages off the pollable channel. It seems to only be getting every second message for some reason, and I can't figure out why.

            Latest xml looks like:
            <si:channel id="input">
                <si:queue capacity="10"/>
            <si:channel id="output">
                <si:queue capacity="10"/>
            <file:inbound-channel-adapter id ="fileinput" directory="/tmp" channel="input" >
            <si:poller task-executor="pool">
                <si:interval-trigger interval="1000"/>
            <bean id="processFile" class="folderpoller.processfile">
            The bean is running the following:
                    PollableChannel channel;
                    channel = (PollableChannel) context.getBean("input");
                    Message<?> recv;
                    recv =;
                    System.out.println("MESSAGE IS:" + recv);
            Can anyone see where the messages are going? I get all the messages on the INFO: line, but it only prints half the messages.


            • #7
              Cron Expression on file inbound adapter

              In the below configuration Am I missing anything?

              <int-file:inbound-channel-adapter id="fileIn" directory="file://${to.transfer}"
              queue-size="10" auto-create-directory="true" channel="localfile">

              <int : poller id="poller" default="false"
              cron="*/10 * 15-16 * * MON-FRI"


              Why cron expression is not working?


              • #8
                Please don't ask the same question in 2 places.