Announcement Announcement Module
Collapse
No announcement yet.
Pause/resume file:inbound-channel-adapter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pause/resume file:inbound-channel-adapter?

    I love Spring Integration; I was able to build a pretty complex system in a week. But I now face a challenge: the program must be able to stop or resume reading incoming files on demand. Is it possible to somehow signal the file:inbound-channel-adapter to stop/resume polling for new files?

    I am kind of stuck now, so your insights are appreciated.

    Thanks,
    Khoa

    PS: I use SI 2.0.0.M2

  • #2
    You can call start/stop on the endpoint directly. For example, if you are using both id and channel in the configuration, inject a reference with the value of that id into some other component (type of dependency to inject could just be a Lifecycle). You can set the "auto-startup" attribute to false if you want to require a manual start.

    In 2.0 M3 (releasing tonight), there is also the first version of a Control Bus, so that you would be able to start/stop by sending a Message. Check out the JMX chapter of the reference manual when it's available.

    Hope that helps.
    Mark

    Comment


    • #3
      Thanks Mark for your quick reply. I'm still a little fuzzy on exactly how to do this. Below is what I have; the bold items were added based on what I understand from your suggestion:

      Code:
      <file:inbound-channel-adapter id="fileReader"
              channel="testco_FilesIn"
      	directory="file:///testco" 
      	filename-pattern="[a-z_]+\.xml\.ready"
      	comparator="comparator"/>
      	
      
      <bean id="comparator" class="CustomFileComparator"/>
      
      <si:router input-channel="testco_FilesIn"
      		   ref="XmlValidator"
      		   method="validate"/>
      
      <bean id="xmlValidator" class="XmlValidator" ref="fileReader"/>
      		   
      <!-- xmlValidator output channels -->
      <si:publish-subscribe-channel id="testco_validXmlFileChannel"/>
      <si:publish-subscribe-channel id="invalidXML"/>
      If the above is correct, how do I configure start/stop to the xmlValidator bean? I saw "init-method" and "destroy-method" attributes, are they the right ones to use?

      Sorry if these questions sound stupid. I still have a lot to learn on Spring and Spring Integration.

      Thanks,
      Khoa

      Comment


      • #4
        I finally got it. Post it here just in case someone else needs it.

        Code:
        <file:inbound-channel-adapter id="fileReader"
                channel="testco_FilesIn"
        	directory="file:///testco" 
        	filename-pattern="[a-z_]+\.xml\.ready"
        	comparator="comparator"/>
        	
        
        <bean id="comparator" class="CustomFileComparator"/>
        
        <si:router input-channel="testco_FilesIn"
        		   ref="XmlValidator"
        		   method="validate"/>
        
        <bean id="xmlValidator" class="XmlValidator">
            <property name="myFileReader">
                <ref bean="fileReader"/>
            </property>
        </bean>
        Then you can call myFileReader.stop()/start() inside XmlValidator.

        I don't like this approach too much since XmlValidator is now coupled with the fileReader. But M3 was just released with JMX support, I'll probably go take a look :-)

        Khoa

        Comment


        • #5
          If you don't have a high polling frequency or a long list of files, you might want to look into a custom FileListFilter, you could implement another interface that is more palatable to the XmlValidator.

          Also you could wrap the file reader in an implementation of that interface to decouple... plenty of options.

          Comment

          Working...
          X