Results 1 to 2 of 2

Thread: apply processor on several items instead of one

  1. #1
    Join Date
    May 2009
    Location
    Marseille, France
    Posts
    3

    Default apply processor on several items instead of one

    Hi all,

    In one of my batch, i need to call a web-service to enrich some data from an item read in db, check some values and then write this enrich item into another table.
    My web-service can support several requests in the same call in order to minimize the number of calls to the web-service. Actually my web-service call is defined as a processor:
    Code:
    <batch:tasklet task-executor="taskExecutor">
      <batch:chunk reader="bookingReader" processor="bookingEnrichWSProcessor"
        writer="bookingCompositeWriter" commit-interval="10" />
    </batch:tasklet>
    It seems that only the item writer can support writing several items in one call using property commit-interval in the step definition.

    What i need is to read items ten by ten with the reader, and call the ws with the 10 items before wirting them again in another table.

    Is it possible to do that in a processor class? or should i port this logic in a writer.

    Thanks for our help
    Last edited by ekki77; Jul 26th, 2012 at 03:05 AM. Reason: bad sentence
    Olivier

  2. #2

    Default

    From my knowledge of Spring Batch, processor will always receive a single element.
    See the section 5.1. Chunk-Oriented Processing
    http://static.springsource.org/sprin...igureStep.html
    Code:
    List items = new Arraylist();
    for(int i = 0; i < commitInterval; i++){
        Object item = itemReader.read()
        Object processedItem = itemProcessor.process(item);
        items.add(processedItem);
    }
    itemWriter.write(items);
    Maybe If your reader returns a List<List<Books>> the processor will receive a List<Books>? Just guessing here, but I think it'll work.
    Last edited by traduz; Jul 26th, 2012 at 09:11 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •