<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
			 xmlns="http://www.springframework.org/schema/integration"
			 xmlns:task="http://www.springframework.org/schema/task"
			 xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
	   http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
	   http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd">

	<channel id="output">
		<queue/>
	</channel>

	<!--Auction scenario-->
	<scatter-gather input-channel="inputAuction" output-channel="output" scatter-channel="auctionChannel">
		<gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"/>
	</scatter-gather>

	<task:executor id="threadPoolTaskExecutor" pool-size="10"/>

	<publish-subscribe-channel id="auctionChannel" apply-sequence="true" task-executor="threadPoolTaskExecutor"/>

	<bridge input-channel="auctionChannel" output-channel="serviceChannel1"/>

	<bridge input-channel="auctionChannel" output-channel="serviceChannel1"/>

	<bridge input-channel="auctionChannel" output-channel="serviceChannel1"/>

	<service-activator input-channel="serviceChannel1" expression="T(java.lang.Math).random() * 10"/>

	<!--Distribution scenario-->
	<scatter-gather input-channel="inputDistribution" output-channel="output" gather-channel="gatherChannel">
		<scatterer>
			<recipient channel="distribution1Channel"/>
			<recipient channel="distribution2Channel"/>
			<recipient channel="distribution3Channel"/>
		</scatterer>
		<gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"/>
	</scatter-gather>

	<channel id="gatherChannel">
		<queue/>
	</channel>

	<bridge input-channel="distribution1Channel" output-channel="serviceChannel2"/>

	<bridge input-channel="distribution2Channel" output-channel="serviceChannel2"/>

	<bridge input-channel="distribution3Channel" output-channel="serviceChannel2"/>

	<service-activator input-channel="serviceChannel2" output-channel="gatherChannel"
					   expression="T(java.lang.Math).random() * 10"/>

	<!--Sync scenario-->

	<gateway id="gateway" default-request-channel="gatewayAuction" default-reply-timeout="10000"/>

	<channel id="gatherChannel2"/>

	<scatter-gather input-channel="gatewayAuction" output-channel="bridgeChannel" scatter-channel="auctionChannel"
					gather-channel="gatherChannel2">
		<gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"/>
	</scatter-gather>

	<bridge input-channel="bridgeChannel"/>

	<chain input-channel="scatterGatherWithinChain" output-channel="output">
		<scatter-gather scatter-channel="auctionChannel"/>
		<splitter/>
	</chain>

</beans:beans>
