1

i have implemented a file inbound channel adapter to poll a directory. where we can receive multiple files, from some other inbound process...out of them we have to pick some unique files to merge. we have implemented a custom filter to perform this job(to get unique files and pass it to the Service activator).

On service Activator we will receive files one by one. and we don't have any clue actually how many files we have receive to merge on current poll from filter class, may be there is only one file or more than one files.

my question is how we can ensure that, how many no of files we are going to receive at Service activator class. So that we can perform our business based on the number of files we have received from Filter class?

Is there any way to let Service activator class know...how many files it will received on that poll from filter class?

1 Answers1

0

The <poller> has an option like:

    <xsd:attribute name="max-messages-per-poll" type="xsd:string">
        <xsd:annotation>
            <xsd:documentation>
                The maximum number of messages that will be produced for each poll. Defaults to
                infinity (indicated by -1) for polling consumers, and 1 for polled
                inbound channel adapters.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:attribute>

So, having there some reasonable value, you will limit your service with on top. If you don't shift each message into separate thread, you can simply have an AtomicInteger in your service to count them. And in the end of poll task you can reset that counter to be ready to calculate again on the next poll. For this purpose you can utilize AbstractMessageSourceAdvice with its afterReceive() implementation like resetting counter when result == null.

See more info in the Reference Manual: http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#conditional-pollers

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks for help...Artem – user2685868 Jun 27 '16 at 08:29
  • Glad to hear! Does it mean that you can accept the answer already? – Artem Bilan Jun 27 '16 at 12:44
  • Actually ..we did some other way ... we have a filter between the channel adapter and the Activator class...so we just introduce a POJO class which has property like, no of files filter has found. Then we read this property from the activator class. Thats it !!. But Thanks for your suggestion, in future if its required i will try to implement this as well. – user2685868 Jul 18 '16 at 08:05