Spring Integration provides support for interacting with Twitter. With the Twitter adapters, you can both receive and send Twitter messages.
Twitter is a social networking and micro-blogging service that enables its users to send and read messages known as tweets. Tweets are text-based posts of up to 140 characters displayed on the author’s profile page and delivered to the author’s subscribers who are known as followers.
Listing 22-67. Maven dependency required
1 2 3 4 5 6 7 8 9 |
<dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-twitter</artifactId> <version>${spring-integration-version}</version> </dependency> |
Listing 22-68 below shows configuration of main Spring Integration namespace and twitter related namespace in the Spring configuration file (twitter-integration-context.xml).
Listing 22-68. Spring Integration Namespace declaration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?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:twitter="http://www.springframework.org/schema/integration/twitter" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter-2.1.xsd"> … </beans> |
For configuring twitter inbound and outbound channel adapter, we need to have TwitterTemplate bean configured as bean in the Spring configuration file as shown in Listing 22-69 below.
Listing 22-69. Configuring twitter template using constructor arguments
1 2 3 4 5 6 7 8 9 10 11 |
<bean id="twitterTemplate" class="org.springframework.social.twitter.api.impl.TwitterTemplate"> <constructor-arg value="4XzBPacJQxyBzzzH"/> <constructor-arg value="AbRxUAvyCtqQtvxFK8w5ZMtMj20KFhB6o"/> <constructor-arg value="21691649-4YZY5iJEOfz2A9qCFd9SjBRGb3HLmIm4HNE"/> <constructor-arg value="AbRxUAvyNCtqQtxFK8w5ZMtMj20KFhB6o"/> </bean> |
TwitterTemplate can also be configured in another way as shown in Listing 22-70 below in which property loader is used to load the various twitter properties from twitter.properties file shown in Listing 22-71 below.
Listing 22-70. Configuring twitter template using twitter.properties file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<context:property-placeholder location="classpath:twitter.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> |
Listing 22-71. Twitter.properties file in which twitter based properties are configured
1 2 3 4 5 6 7 |
twitter.oauth.consumerKey=4XzBPacJQxyBzzzH twitter.oauth.consumerSecret=AbRxUAvyCtqQtvxFK8w5ZMtMj20KFhB6o twitter.oauth.accessToken=21691649-4YZY5iJEOfz2A9qCFd9SjBRGb3HLmIm4HNE twitter.oauth.accessTokenSecret=AbRxUAvyNCtqQtxFK8w5ZMtMj20KFhB6o |
Listing 22-72 below shows configuring twitter outbound channel adapter in Spring configuration file.
Listing 22-72. Configuring twitter outbound channel adapter in Spring configuration file
1 2 3 |
<int:channel id="twitterChannel"/> <twitter:outbound-channel-adapter twitter-template="twitterTemplate" channel="twitterChannel"/> |
Listing 22-73 below shows configuring twitter inbound channel adapter in Spring configuration file.
Listing 22-73. Configuring twitter inbound channel adapter in Spring configuration file
1 2 3 4 5 6 7 |
<int:channel id="twitterChannel"/> <twitter:inbound-channel-adapter channel="twitterChannel" twitter-template="twitterTemplate"> <int:poller fixed-rate="5000" max-messages-per-poll="3"/> </twitter:inbound-channel-adapter> |
Page Visitors: 13052

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu