<?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:amqp="http://www.springframework.org/schema/integration/amqp"
	xmlns:int="http://www.springframework.org/schema/integration"
	xmlns:rabbit="http://www.springframework.org/schema/rabbit"
	xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp https://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
		http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/rabbit https://www.springframework.org/schema/rabbit/spring-rabbit.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

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

	<rabbit:template id="amqpTemplateConfirms" connection-factory="connectionFactory"
			reply-timeout="10" message-converter="ctConverter" />

	<amqp:outbound-gateway id="pcGateway"
						   request-channel="pcRequestChannel"
						   reply-channel="fromRabbit"
						   exchange-name=""
						   routing-key="#{queue.name}"
						   mapped-request-headers="STANDARD_REQUEST_HEADERS,foo*"
						   requires-reply="false"
						   amqp-template="amqpTemplateConfirms"
						   confirm-correlation-expression="headers['amqp_confirmCorrelationData']"
						   confirm-ack-channel="ackChannel" />

	<int:channel id="pcRequestChannel"/>

	<rabbit:template id="amqpTemplateConfirmsMC" connection-factory="connectionFactory" reply-timeout="10" />

	<amqp:outbound-gateway request-channel="pcMessageCorrelationRequestChannel"
						   reply-channel="fromRabbit"
						   exchange-name=""
						   routing-key="#{queue.name}"
						   mapped-request-headers="foo*"
						   requires-reply="false"
						   amqp-template="amqpTemplateConfirmsMC"
						   confirm-correlation-expression="#this"
						   confirm-ack-channel="ackChannel" />

	<int:channel id="pcMessageCorrelationRequestChannel" />

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

	<rabbit:template id="amqpTemplateConfirmsAdapter" connection-factory="connectionFactory"/>

	<amqp:outbound-channel-adapter id="withPublisherConfirms" channel="pcRequestChannelForAdapter"
								   exchange-name=""
								   routing-key="#{queue.name}"
								   mapped-request-headers="foo*"
								   amqp-template="amqpTemplateConfirmsAdapter"
								   confirm-correlation-expression="headers['amqp_confirmCorrelationData']"
								   confirm-ack-channel="ackChannel" >
		<int:poller fixed-delay="100"/>
	</amqp:outbound-channel-adapter>

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

	<rabbit:template id="multiSendTemplate" connection-factory="multiSendFactory"/>

	<amqp:outbound-channel-adapter id="multiSendAdapter" channel="multiSendChannel"
								   exchange-name=""
								   routing-key="#{queue.name}"
								   amqp-template="multiSendTemplate"
								   multi-send="true"
								   wait-for-confirm="true"/>

	<int:channel id="multiSendChannel"/>

	<rabbit:template id="amqpTemplateReturns" connection-factory="connectionFactory" mandatory="true" />

	<amqp:outbound-channel-adapter id="withReturns" channel="returnRequestChannel"
								   exchange-name=""
								   routing-key="#{queue.name + queue.name}"
								   mapped-request-headers="foo*"
								   amqp-template="amqpTemplateReturns"
								   confirm-correlation-expression="headers['corrData']"
								   return-channel="returnChannel" />

	<int:channel id="returnRequestChannel"/>

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

	<amqp:outbound-channel-adapter id="withContentTypeConverter" channel="ctRequestChannel"
								   exchange-name=""
								   routing-key="#{queue.name}"
								   amqp-template="amqpTemplateContentTypeConverter" />

	<int:channel id="ctRequestChannel"/>

	<rabbit:template id="amqpTemplateContentTypeConverter"
			connection-factory="connectionFactory" message-converter="ctConverter" />

	<bean id="ctConverter" class="org.springframework.amqp.support.converter.ContentTypeDelegatingMessageConverter">
		<property name="delegates">
			<map>
				<entry key="application/json">
					<bean class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter" />
				</entry>
			</map>
		</property>
	</bean>

	<rabbit:connection-factory id="connectionFactory"
		host="localhost" publisher-returns="true" confirm-type="CORRELATED" />

	<rabbit:connection-factory id="multiSendFactory"
		host="localhost" publisher-returns="true" confirm-type="SIMPLE" />

	<rabbit:admin connection-factory="connectionFactory" />

	<rabbit:queue id="queue" />

</beans>
