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

	<bean id="redisConnectionFactory" class="org.springframework.integration.redis.RedisContainerTest"
		  factory-method="connectionFactory"/>

	<int-redis:store-inbound-channel-adapter id="listAdapter"
											 connection-factory="redisConnectionFactory"
											 key-expression="'presidents'"
											 channel="transformChannel"
											 auto-startup="false"
											 collection-type="LIST">
		<int:poller fixed-rate="2000" max-messages-per-poll="10"/>
	</int-redis:store-inbound-channel-adapter>

	<int-redis:store-inbound-channel-adapter id="listAdapterWithSynchronization"
											 connection-factory="redisConnectionFactory"
											 key-expression="'presidents'"
											 channel="transformChannel"
											 auto-startup="false">
		<int:poller fixed-rate="2000" max-messages-per-poll="10">
			<int:transactional synchronization-factory="syncFactory"/>
		</int:poller>
	</int-redis:store-inbound-channel-adapter>

	<int-redis:store-inbound-channel-adapter id="listAdapterWithSynchronizationAndRollback"
											 connection-factory="redisConnectionFactory"
											 key-expression="'presidents'"
											 channel="redisFailChannel"
											 auto-startup="false">
		<int:poller fixed-rate="2000" max-messages-per-poll="10">
			<int:transactional synchronization-factory="syncFactory"/>
		</int:poller>
	</int-redis:store-inbound-channel-adapter>

	<int:channel id="redisFailChannel"/>

	<int-redis:store-inbound-channel-adapter id="listAdapterWithSynchronizationAndRedisTemplate"
											 redis-template="redisTemplate"
											 key-expression="'presidents'"
											 channel="transformChannel"
											 auto-startup="false">
		<int:poller fixed-rate="2000" max-messages-per-poll="10">
			<int:transactional synchronization-factory="syncFactory"/>
		</int:poller>
	</int-redis:store-inbound-channel-adapter>

	<int:transaction-synchronization-factory id="syncFactory">
		<int:after-commit expression="#store.rename('bar')"/>
		<int:after-rollback expression="#store.rename('baz')"/>
	</int:transaction-synchronization-factory>

	<int-redis:store-inbound-channel-adapter id="listAdapterWithSynchronizationBeforeCommit"
											 redis-template="redisTemplate"
											 key-expression="'presidents'"
											 channel="transformChannel"
											 auto-startup="false">
		<int:poller fixed-rate="2000" max-messages-per-poll="10" error-channel="adapterErrors">
			<int:transactional synchronization-factory="syncFactory2"/>
		</int:poller>
	</int-redis:store-inbound-channel-adapter>

	<int:channel id="adapterErrors">
		<int:queue/>
	</int:channel>

	<int:transaction-synchronization-factory id="syncFactory2">
		<int:before-commit expression="5/0"/>
	</int:transaction-synchronization-factory>

	<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
		<property name="connectionFactory" ref="redisConnectionFactory"/>
		<property name="keySerializer">
			<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
		</property>
		<property name="hashKeySerializer">
			<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
		</property>
	</bean>

	<int:transformer input-channel="transformChannel" output-channel="redisChannel" expression="payload.size()"/>

	<int:channel id="redisChannel">
		<int:queue/>
	</int:channel>

	<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>

</beans>
