<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:integration="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:int-jms="http://www.springframework.org/schema/integration/jms" xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
		http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<import resource="classpath:/simple-job-launcher-context.xml" />

	<import resource="classpath:/jms-context.xml" />

	<int-jms:outbound-gateway request-channel="requests" request-destination-name="requests"
		reply-channel="staging" receive-timeout="30000">
		<integration:poller fixed-rate="200" task-executor="taskExecutor" />
	</int-jms:outbound-gateway>

	<task:executor id="taskExecutor" pool-size="2" />

	<channel id="requests" xmlns="http://www.springframework.org/schema/integration">
		<queue />
	</channel>

	<channel id="staging" xmlns="http://www.springframework.org/schema/integration" />

	<int-jms:inbound-gateway request-channel="worker" request-destination-name="requests"
		concurrent-consumers="2" />

	<service-activator ref="stepExecutionRequestHandler" input-channel="worker"
		xmlns="http://www.springframework.org/schema/integration" />
	<aggregator ref="partitionHandler" input-channel="staging" xmlns="http://www.springframework.org/schema/integration" />

	<!-- This is the "remote" worker (which in this case is local) -->
	<bean id="stepExecutionRequestHandler" class="org.springframework.batch.integration.partition.StepExecutionRequestHandler"
		p:jobExplorer-ref="jobExplorer" p:stepLocator-ref="stepLocator" />

	<bean id="stepLocator" class="org.springframework.batch.integration.partition.BeanFactoryStepLocator" />

	<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean">
		<property name="repositoryFactory" ref="&amp;jobRepository" />
	</bean>

	<bean id="partitionHandler" class="org.springframework.batch.integration.partition.MessageChannelPartitionHandler">
		<property name="messagingOperations">
			<bean class="org.springframework.integration.core.MessagingTemplate">
				<property name="defaultChannel" ref="requests" />
				<property name="receiveTimeout" value="10000" />
			</bean>
		</property>
		<property name="stepName" value="step1" />
		<property name="gridSize" value="2" />
	</bean>

	<job id="job1" xmlns="http://www.springframework.org/schema/batch">
		<step id="step1-master">
			<partition handler="partitionHandler" partitioner="partitioner" />
		</step>
	</job>

	<bean id="partitioner" class="org.springframework.batch.core.partition.support.SimplePartitioner" />

	<step id="step1" xmlns="http://www.springframework.org/schema/batch">
		<tasklet>
			<chunk commit-interval="10">
				<reader>
					<bean class="org.springframework.batch.integration.partition.ExampleItemReader" scope="step"
						xmlns="http://www.springframework.org/schema/beans" />
				</reader>
				<writer>
					<bean class="org.springframework.batch.integration.partition.ExampleItemWriter" xmlns="http://www.springframework.org/schema/beans" />
				</writer>
			</chunk>
		</tasklet>
	</step>

</beans>
