Announcement Announcement Module
Collapse
No announcement yet.
apply processor on several items instead of one Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 03:05 AM. Reason: bad sentence

  • #2
    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, 09:11 AM.

    Comment

    Working...
    X