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

	<context:mbean-server/>

	<int-jmx:mbean-export id="integrationMBeanExporter" default-domain="spring.application"/>

	<context:mbean-export default-domain="spring.application"/>

	<int:message-history/>

	<context:component-scan base-package="org.springframework.integration.service" />

	<!-- As of Twitter API version 1.1, users must be authenticated to perform searches
		so, by default, we run with a dummy adapter only see README if you want a real twitter search
		where this adapter will be replaced by a real one -->

	<int:inbound-channel-adapter id="twitter" channel="twitterChannel" method="getTweet">
		<bean class="org.springframework.integration.service.impl.DummyTwitter"/>
		<int:poller fixed-delay="30000"/>
	</int:inbound-channel-adapter>

	<!-- This dummy adapter is used to generate traffic for the monitoring demo in addition to the
		 above adapter, or a real twitter adapter -->

	<int:inbound-channel-adapter id="dummyTwitter" channel="twitterChannel" method="getTweet">
		<bean class="org.springframework.integration.service.impl.DummyTwitter"/>
		<int:poller fixed-delay="5000"/>
	</int:inbound-channel-adapter>

	<int:header-enricher id="addFooHeader" input-channel="twitterChannel" output-channel="twitterChannel2">
		<int:correlation-id value="foo"/>
	</int:header-enricher>

	<int:transformer id="noopButSlowTransformer" input-channel="twitterChannel2" output-channel="twitterChannel3">
		<int-groovy:script>
			Thread.sleep(1000)
			payload
		</int-groovy:script>
	</int:transformer>

	<int:service-activator id="twitterServiceActivator" input-channel="twitterChannel3"
						ref="twitterService" method="addTwitterMessages" />

	<bean id="twitterService" class="org.springintegration.service.impl.DefaultTwitterService"/>

	<int:publish-subscribe-channel id="twitterChannel">
		<int:interceptors>
			<int:wire-tap channel="logger" />
			<bean class="org.springintegration.PayloadAwareTimingInterceptor">
				<constructor-arg>
					<array>
						<value>java.lang.String</value>
						<value>org.springframework.social.twitter.api.Tweet</value>
					</array>
				</constructor-arg>
			</bean>
		</int:interceptors>
	</int:publish-subscribe-channel>

	<int:publish-subscribe-channel id="logger" />
	
	<int:logging-channel-adapter id="loggingAdapter" channel="logger" level="INFO"
		expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text" />

	<int:bridge id="bridgeToQueueChannel"
		input-channel="logger" output-channel="queue"/>
	
	<int:channel id="queue">
		<int:queue/>
	</int:channel>

	<int:transformer id="tweetToStringTransformer"
		input-channel="twitterChannel"
		output-channel="twitterPublishChannel"
		expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text"/>

	<int:channel id="twitterPublishChannel"/>

	<int-jmx:notification-publishing-channel-adapter
		channel="twitterPublishChannel"
		default-notification-type="TWEET"
		object-name="spring.application:type=TweetPublisher,name=tweeter"/>

	<int:channel id="controlBusChannel"/>

	<int:control-bus id="controlBus" input-channel="controlBusChannel"/>

	<beans profile="twitter">

		<!-- As of Twitter API version 1.1, users must be authenticated to perform searches -->

		<context:property-placeholder location="classpath:oauth.properties"/>

		<bean id="twitterTemplate"
			class="org.springframework.social.twitter.api.impl.TwitterTemplate">
			<constructor-arg value="${twitter.oauth.consumerKey}" />
			<constructor-arg value="${twitter.oauth.consumerSecret}" />
			<constructor-arg value="${twitter.oauth.accessToken}" />
			<constructor-arg value="${twitter.oauth.accessTokenSecret}" />
		</bean>

		<int-twitter:search-inbound-channel-adapter id="twitter" query="#springintegration"
				twitter-template="twitterTemplate"
				channel="twitterChannel"
				auto-startup="true">
			<int:poller fixed-rate="30000" max-messages-per-poll="10" />
		</int-twitter:search-inbound-channel-adapter>

	</beans>

</beans>
