Add remote partitioning samples
This commit also fixes the code examples in the remote partitioning section of the documentation Resolves BATCH-2730
This commit is contained in:
@@ -1051,6 +1051,10 @@ configuration:
|
||||
.Java Configuration
|
||||
[source, java, role="javaContent"]
|
||||
----
|
||||
|
||||
/*
|
||||
* Configuration of the master side
|
||||
*/
|
||||
@Bean
|
||||
public PartitionHandler partitionHandler() {
|
||||
MessageChannelPartitionHandler partitionHandler = new MessageChannelPartitionHandler();
|
||||
@@ -1064,6 +1068,11 @@ public PartitionHandler partitionHandler() {
|
||||
return partitionHandler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QueueChannel outboundReplies() {
|
||||
return new QueueChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectChannel outboundRequests() {
|
||||
return new DirectChannel();
|
||||
@@ -1078,44 +1087,13 @@ public IntegrationFlow outboundJmsRequests() {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectChannel inboundRequests() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
|
||||
public IntegrationFlow inboundJmsRequests() {
|
||||
return IntegrationFlows
|
||||
.from(Jms.messageDrivenChannelAdapter(connectionFactory())
|
||||
.configureListenerContainer(c -> c.subscriptionDurable(false))
|
||||
.destination("requestsQueue"))
|
||||
.channel(inboundRequests())
|
||||
.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StepExecutionRequestHandler stepExecutionRequestHandler() {
|
||||
StepExecutionRequestHandler stepExecutionRequestHandler = new StepExecutionRequestHandler();
|
||||
stepExecutionRequestHandler.setJobExplorer(jobExplorer);
|
||||
stepExecutionRequestHandler.setStepLocator(stepLocator());
|
||||
return stepExecutionRequestHandler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "inboundRequests", outputChannel = "outboundStaging")
|
||||
public StepExecutionRequestHandler serviceActivator() throws Exception {
|
||||
return stepExecutionRequestHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectChannel outboundStaging() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow outboundJmsStaging() {
|
||||
return IntegrationFlows.from("outboundStaging")
|
||||
.handle(Jms.outboundGateway(connectionFactory())
|
||||
.requestDestination("stagingQueue"))
|
||||
.get();
|
||||
@ServiceActivator(inputChannel = "inboundStaging")
|
||||
public AggregatorFactoryBean partitioningMessageHandler() throws Exception {
|
||||
AggregatorFactoryBean aggregatorFactoryBean = new AggregatorFactoryBean();
|
||||
aggregatorFactoryBean.setProcessorBean(partitionHandler());
|
||||
aggregatorFactoryBean.setOutputChannel(outboundReplies());
|
||||
// configure other propeties of the aggregatorFactoryBean
|
||||
return aggregatorFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -1133,19 +1111,48 @@ public IntegrationFlow inboundJmsStaging() {
|
||||
.get();
|
||||
}
|
||||
|
||||
/*
|
||||
* Configuration of the worker side
|
||||
*/
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "inboundStaging")
|
||||
public AggregatorFactoryBean partitioningMessageHandler() throws Exception {
|
||||
AggregatorFactoryBean aggregatorFactoryBean = new AggregatorFactoryBean();
|
||||
aggregatorFactoryBean.setProcessorBean(partitionHandler());
|
||||
aggregatorFactoryBean.setOutputChannel(outboundReplies());
|
||||
...
|
||||
return aggregatorFactoryBean;
|
||||
public StepExecutionRequestHandler stepExecutionRequestHandler() {
|
||||
StepExecutionRequestHandler stepExecutionRequestHandler = new StepExecutionRequestHandler();
|
||||
stepExecutionRequestHandler.setJobExplorer(jobExplorer);
|
||||
stepExecutionRequestHandler.setStepLocator(stepLocator());
|
||||
return stepExecutionRequestHandler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QueueChannel outboundReplies() {
|
||||
return new QueueChannel();
|
||||
@ServiceActivator(inputChannel = "inboundRequests", outputChannel = "outboundStaging")
|
||||
public StepExecutionRequestHandler serviceActivator() throws Exception {
|
||||
return stepExecutionRequestHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectChannel inboundRequests() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
|
||||
public IntegrationFlow inboundJmsRequests() {
|
||||
return IntegrationFlows
|
||||
.from(Jms.messageDrivenChannelAdapter(connectionFactory())
|
||||
.configureListenerContainer(c -> c.subscriptionDurable(false))
|
||||
.destination("requestsQueue"))
|
||||
.channel(inboundRequests())
|
||||
.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectChannel outboundStaging() {
|
||||
return new DirectChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow outboundJmsStaging() {
|
||||
return IntegrationFlows.from("outboundStaging")
|
||||
.handle(Jms.outboundGateway(connectionFactory())
|
||||
.requestDestination("stagingQueue"))
|
||||
.get();
|
||||
}
|
||||
----
|
||||
|
||||
@@ -1168,8 +1175,12 @@ You must also ensure that the partition `handler` attribute maps to the `partiti
|
||||
public Job personJob() {
|
||||
return jobBuilderFactory.get("personJob")
|
||||
.start(stepBuilderFactory.get("step1.master")
|
||||
.partitioner(partitionHandler())
|
||||
.partitioner("step1.worker", partitioner())
|
||||
.partitionHandler(partitionHandler())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
----
|
||||
|
||||
You can find a complete example of a remote partitioning job
|
||||
link:$$https://github.com/spring-projects/spring-batch/tree/master/spring-batch-samples#remote-partitioning-sample$$[here].
|
||||
|
||||
Reference in New Issue
Block a user