0

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=""/>
Debopam
  • 3,198
  • 6
  • 41
  • 72
  • I'm not sure I understand your question. You are asking `how to use batch-int configurations in XML for below two xml element configurations?`, but the two xml snippets you shared are actually how to use them, you just need to fill in the attributes with reference to actual beans. Is that what you are looking for? – Mahmoud Ben Hassine Feb 24 '21 at 12:42
  • Yes I need some working example of batch integration using XML – Debopam Feb 24 '21 at 16:48
  • or if we have some Spring batch 3.x to 4.x migration document that might help as well. – Debopam Feb 24 '21 at 16:49

1 Answers1

1

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"
/>
Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50