springspring-batchspring-batch-integration

Spring batch 4.x integration XML configuration for remote chunking


I am upgrading Spring batch from 3.x to 4.3. Currently we are using Spring batch integration and XML configuration for putting & receiving messages via MQ. Spring batch 4 introduced @EnableBatchIntegration and corresponding XML XSDs are

xmlns:batch-int="http://www.springframework.org/schema/batch-integration"

http://www.springframework.org/schema/batch-integration
    https://www.springframework.org/schema/batch-integration/spring-batch-integration.xsd

Could you please let me know how to use batch-int configurations in XML for below two xml element configurations?

<batch-int:remote-chunking-manager message-template="" step="" reply-channel="" id=""/>
<batch-int:remote-chunking-worker output-channel="" item-writer="" input-channel="" id=""/>

Solution

  • Spring Batch reference documentation provides a toggle (at the top of each page) to show code examples in XML or Java configuration styles (or both). However, there seems to be only Java config examples in the remote chunking/partitioning sections, the XML equivalent is missing. I created an issue for that: https://github.com/spring-projects/spring-batch/issues/3858.

    In the meantime, here are the equivalent XML snippets for remote chunking:

    Worker setup

    /// java config
    @Bean
    public IntegrationFlow worker() {
        return workerBuilder
                .inputChannel(requests()) // requests received from the manager
                .outputChannel(replies()) // replies sent to the manager
                .itemProcessor(itemProcessor())
                .itemWriter(itemWriter())
                .build();
    }
    
    /// xml config
    <batch-int:remote-chunking-worker
        id="worker"
        input-channel="requests"
        output-channel="replies"
        item-processor="itemProcessor"
        item-writer="itemWriter"
    />
    

    Manager setup

    /// java config
    @Bean
    public TaskletStep managerStep() {
        return managerStepBuilderFactory.get("managerStep")
                .chunk(100)
                .reader(itemReader())
                .outputChannel(requests()) // requests sent to workers
                .inputChannel(replies())   // replies received from workers
                .build();
    }
    
    // xml config: there no one to one mapping, but you can use the following:
    <batch-int:remote-chunking-manager
       id="managerStep"
       message-template="messageTemplate" <!-- template with "requests" as default destination -->
       step="step" <!-- reference to a chunk-oriented step with required itemReader and chunkSize=100, the writer will be replaced with a ChunkMessageChannelItemWriter automatically -->
       reply-channel="replies"
    />