Results 1 to 3 of 3

Thread: Multiple writers or readers.

  1. #1
    Join Date
    Dec 2011
    Posts
    8

    Default Multiple writers or readers.

    Hi guys,


    i have a question about spring batch. The other day i was reading the book "Spring Batch In Action" and there was a statement that was saying that every step is formed by three elements: a reader, a processor and a writer. So my question is: Is it possible to have more than one reader or writer associated to a step ?

    Example for writer: Imagine you would like to write the processed data to a file and to a database, or to two different databases.

    If this is not possible, how can we achieve this behavior ?

    Thank you.

  2. #2

    Default

    out of the box you can:



    for more than one reader i have an example in my github repository, but this is a "unify all read items from all readers to one item for each read sequence"

    example spring configuration:

    Code:
        <bean id="compositeItemReader" class="de.langmi.spring.batch.examples.readers.support.CompositeItemStreamReader">
            <property name="unifyingMapper">
                <bean class="de.langmi.spring.batch.examples.readers.support.DefaultUnifyingStringItemsMapper" />
            </property>
            <property name="itemReaderStreams">
                <list>
                    <ref bean="itemReader1" />
                    <ref bean="itemReader2" />
                </list>
            </property>
        </bean>
    
        <bean id="itemReader1" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
            <property name="name" value="itemReader1" />
            <property name="resource" value="#{jobParameters['input.file.1']}" />
            <property name="lineMapper">
                <bean class="org.springframework.batch.item.file.mapping.PassThroughLineMapper" />
            </property>
            <property name="strict" value="true" />
        </bean>
    
        <bean id="itemReader2" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
            <property name="name" value="itemReader2" />
            <property name="resource" value="#{jobParameters['input.file.2']}" />
            <property name="lineMapper">
                <bean class="org.springframework.batch.item.file.mapping.PassThroughLineMapper" />
            </property>
            <property name="strict" value="true" />
        </bean>

  3. #3
    Join Date
    Dec 2011
    Posts
    8

    Default

    Thank you, that helped.

Posting Permissions

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