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

	<jdbc:embedded-database id="dataSource" type="H2"/>

	<jdbc:initialize-database ignore-failures="DROPS">
		<jdbc:script location="org/springframework/integration/jdbc/schema-drop-h2.sql"/>
		<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql" />
	</jdbc:initialize-database>

	<int-jdbc:message-store id="messageStore" data-source="dataSource"/>

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

	<bean id="storeQueue" class="org.springframework.integration.store.MessageGroupQueue">
		<constructor-arg ref="messageStore"/>
		<constructor-arg value="JdbcMessageStoreChannelIntegrationTests"/>
		<constructor-arg ref="lock"/>
	</bean>

	<int:channel id="output"/>

	<int:logging-channel-adapter channel="output"/>

	<service-activator id="service-activator"
					   input-channel="input" output-channel="output"
					   xmlns="http://www.springframework.org/schema/integration">
		<beans:bean
				class="org.springframework.integration.jdbc.store.JdbcMessageStoreChannelIntegrationTests$Service"/>
		<poller fixed-rate="200">
			<advice-chain>
				<ref bean="txAdvice"/>
				<ref bean="lock"/>
			</advice-chain>
		</poller>
	</service-activator>

	<bean id="lock" class="org.springframework.integration.jdbc.LockInterceptor"/>
	<tx:advice id="txAdvice">
		<tx:attributes>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>

	<bean id="transactionManager"
		  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
		<property name="defaultTimeout" value="10"/>
	</bean>

	<int:header-enricher input-channel="routingSlip" output-channel="input">
		<int:routing-slip value="@myService.nextPath(request, reply)"/>
	</int:header-enricher>

</beans>
