Search code examples
javaspring-integrationsplitter

Spring integration Splitter task execution


I'm working on a Spring Integration application.

I have an inbound channel adapter that read a directory Then a splitter that split the File into lines Finally an udp outbound channel adapter that sends the lines

<int-file:inbound-channel-adapter prevent-duplicates="false"
          id="filesIn" directory="file:input" channel="inputFiles" />

<int:splitter  input-channel="inputFiles" output-channel="udpChannel_11111"
         expression="T(org.apache.commons.io.FileUtils).lineIterator(payload)" />

<!-- Define UDP outbound channel -->
<int:channel id="udpChannel_11111" />
<int-ip:udp-outbound-channel-adapter channel="udpChannel_11111"
        host="192.168.0.1" port="11111" />

I would like to send a line every one second

I can do this by define my own splitter and wait 1s each time I read a line, but I would like to know if it's possible to do it in the xml file to be as simple as possible.

Thanks in advance


Solution

  • Put the messages in a QueueChannel and use a poller to send once a second.

    The UDP channel adapter doesn't currently support a poller, but you can use a bridge...

    <int:splitter  input-channel="inputFiles" output-channel="udpChannel_11111"
         expression="T(org.apache.commons.io.FileUtils).lineIterator(payload)" />
    
    <int:channel id="toBridge">
        <int:queue />
    </int:channel>
    
    <int:bridge input-channel="toBridge" output-channel="udpChannel_11111">
        <int:poller fixed-delay="1000" max-messages-per-poll="1" />
    </int:bridge>
    

    Bear in mind, though, that the file will quickly be loaded into the queue channel and you may have memory issues if it's very large.