INTSAMPLES-119 Update Monitor for Twitter OAuth

Twitter now requires authentication.

Disable the real twitter adapter by default; enable it
with spring.profile "twitter" - requires the user to get
real oauth tokens.

Replicate oauth setup instructions from the twitter sample.

Add note to README for enabling the real twitter adapter.

Add .gitignore so committers can keep their real credentials
in, say, 'oauth.properties.foo'.

Add note about `SpringIntegrationTest`.

Update dummy tweets to use new icon.

INTSAMPLES-119 Polishing

- Fix 'twitterTemplate' bean name
- Add content to log and JMX Notification

JIRA: https://jira.springsource.org/browse/INTSAMPLES-119
This commit is contained in:
Gary Russell
2013-11-19 14:09:55 +02:00
committed by Artem Bilan
parent 630d1cf009
commit e190c160f1
6 changed files with 88 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ public class DummyTwitter {
"Spring Integration is the coolest Enterprise Integration project",
new Date(),
"SomeUser",
"http://a0.twimg.com/profile_images/1598911687/ICO_S2_Bug_normal.png",
"https://pbs.twimg.com/profile_images/378800000502646541/992d3596458fca87741b8e93e7df0860_normal.png",
0L,
0L,
null,

View File

@@ -23,12 +23,19 @@
<context:component-scan base-package="org.springframework.integration.service" />
<int-twitter:search-inbound-channel-adapter id="twitter" query="#springintegration"
channel="twitterChannel" auto-startup="true">
<int:poller fixed-rate="30000" max-messages-per-poll="10" />
</int-twitter:search-inbound-channel-adapter>
<!-- 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="dummyAdapter" channel="twitterChannel" method="getTweet">
<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>
@@ -66,7 +73,7 @@
<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" />
expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text" />
<int:bridge id="bridgeToQueueChannel"
input-channel="logger" output-channel="queue"/>
@@ -78,7 +85,7 @@
<int:transformer id="tweetToStringTransformer"
input-channel="twitterChannel"
output-channel="twitterPublishChannel"
expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser"/>
expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text"/>
<int:channel id="twitterPublishChannel"/>
@@ -91,4 +98,27 @@
<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>

View File

@@ -0,0 +1,4 @@
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
twitter.oauth.accessToken=
twitter.oauth.accessTokenSecret=

View File

@@ -9,6 +9,14 @@
<param-value>classpath:META-INF/spring/integration/spring-integration-context.xml</param-value>
</context-param>
<!-- uncomment this if you want to use real twitter and have set oauth keys -->
<!--
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>twitter</param-value>
</context-param>
-->
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>