<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:int="http://www.springframework.org/schema/integration"
	xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
	xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
	xmlns:amq="http://activemq.apache.org/schema/core"
	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/integration/stream https://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
		http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
		http://activemq.apache.org/schema/core https://activemq.apache.org/schema/core/activemq-core-5.4.2.xsd">

	<!-- Set up a live broker with a transport connector at port 61616 (default amq port)
	We imported the ActiveMQ schema so we can use the schema support. When this application shuts down,
	so does the broker. You can omit the embedded declaration here and set up the broker stand alone and
	use the standard ActiveMQ HighAvailability mechanism. You can also use the peer:// scheme to link up
	multiple embedded brokers. See the docs for more: https://activemq.apache.org/peer-transport-reference.html
	-->
	<amq:broker brokerName="cafe-broker">
		<amq:transportConnectors>
			<amq:transportConnector name="openwire" uri="tcp://localhost:61616"/>
		</amq:transportConnectors>
	</amq:broker>

	<!--Define an error channel that is backed by ActiveMQ. Note, by design, the error channel that's
	created by default by SI if you don't declare one specifically will use the pub/sub messaging domain. Because
	of that, i've chosen to keep the same messaging domain when defining the error channel explicitly. Note,
	you can leave out this declaration, but then your error channel won't be backed by jms and can't participate
	in the same advantages as those that are backed by JMS -->
	<int-jms:publish-subscribe-channel id="errorChannel" topic-name="org.springframework.integration.samples.cafe.errors"/>

	<int:gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>

	<!-- each order has a collection of order items that is split apart to be processed -->
	<int-jms:channel id="orders" queue-name="org.springframework.integration.samples.cafe.orders" />
	<int:splitter input-channel="orders" expression="payload.items" output-channel="drinks"/>

	<!-- The router sends different drink orders on different paths -->
	<int-jms:channel id="drinks" queue-name="org.springframework.integration.samples.cafe.drinks"/>
	<int:router input-channel="drinks"  expression="payload.iced ? 'coldDrinks' : 'hotDrinks'"/>

	<!-- individual order items are processed by the barista -->
	<!-- Note, these channels were defined as "pollable" in the original SI config files. To achieve the
	same thing with a JMS-backed channel, set the "message-driven" property to "false"-->
	<int-jms:channel id="coldDrinks" queue-name="org.springframework.integration.samples.cafe.drinks.cold" message-driven="false"/>
	<int:service-activator input-channel="coldDrinks" ref="barista" method="prepareColdDrink" output-channel="preparedDrinks"/>

	<!-- individual order items are processed by the barista -->
	<!-- Note, these channels were defined as "pollable" in the original SI config files. To achieve the
	same thing with a JMS-backed channel, set the "message-driven" property to "false"-->
	<int-jms:channel id="hotDrinks" queue-name="org.springframework.integration.samples.cafe.drinks.hot" message-driven="false"/>
	<int:service-activator input-channel="hotDrinks" ref="barista" method="prepareHotDrink" output-channel="preparedDrinks"/>

	<!-- drink order items are aggregated in a call to the waiter -->
	<int-jms:channel id="preparedDrinks" queue-name="org.springframework.integration.samples.cafe.drinks.prepared"/>
	<int-jms:channel id="deliveriesChannel" queue-name="org.springframework.integration.samples.cafe.deliveres"/>
	<int:aggregator input-channel="preparedDrinks"  method="prepareDelivery" output-channel="deliveriesChannel">
		<bean class="org.springframework.integration.samples.cafe.xml.Waiter"/>
	</int:aggregator>

	<int-stream:stdout-channel-adapter id="deliveries" channel="deliveriesChannel"/>

	<bean id="barista" class="org.springframework.integration.samples.cafe.xml.Barista"/>

	<int:poller id="poller" default="true" fixed-delay="1000"/>

</beans>
