<?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"
	   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/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">

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

	<jdbc:initialize-database data-source="dataSource">
		<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" />

	<int:channel id="input">
		<int:queue ref="queue"/>
	</int:channel>

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

	<int:service-activator id="service-activator" input-channel="input" output-channel="nullChannel">
		<beans:bean class="org.springframework.integration.jdbc.store.JdbcMessageStoreChannelTests$Service" />
		<int:poller fixed-rate="2000">
			<int:transactional synchronization-factory="transactionSynchronizationFactory"/>
		</int:poller>
	</int:service-activator>

	<int:transaction-synchronization-factory id="transactionSynchronizationFactory">
		<int:after-commit expression="@afterCommitLatch.countDown()"/>
	</int:transaction-synchronization-factory>

	<bean id="afterCommitLatch" class="java.util.concurrent.CountDownLatch">
		<constructor-arg value="1"/>
	</bean>

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

</beans>
