Java Reference
In-Depth Information
Many people, from the everyman to the super famous, use Twitter. Reports have it as the third
biggest social networking site as of this writing. Some people (presidents, celebrities, and so on) have
hundreds of thousands of followers, and at least one has in excess of a million followers. As you can
imagine, the difficulties and logistics of managing a graph as complex and sprawling as the one Twitter
manages can be frustrating and has been the source of many well publicized outages.
Twitter furnishes a REST API through which users can interact with the system. The API lets one do
anything she might do from the web site: follow users, stop following users, update status, and so on.
The API is concise and has many language bindings already available. In the example, you'll use one
project's API, called Twitter4J, which nicely wraps the API in simple approachable API calls.
Twitter4J was created by Yusuke Yamamoto and is available under the BSD license. It's available in
the Maven repositories, and it has a fairly active support mailing list. If you want to find more about
Twitter4J, visit http://yusuke.homeip.net .
Twitter Messages
In the first example, you'll build support for receiving messages, not for sending them. The second
example will feature support for outbound messages. In particular, you'll build support for receiving the
status updates of the people to which a particular account is subscribed, or following .
There are other types of Twitter messages. Although you won't build adapters for every type, it won't
be difficult to imagine how it's done once you've completed the examples. Twitter supports direct
messaging, in which you can specify that one recipient only sees the contents of the message; this is
peer-to-peer messaging , roughly analogous to using SMS messaging. Twitter also supports receiving
messages in which your screen handle was mentioned. These messages can often be messages directed
to you and others, messages discussing you, or messages reposting ( retweeting ) something you said
already.
A Simple MessageSource
There are two ways to build an adapter, using principally the same technique. You can create a class that
implements MessageSource , or you can configure a method that should be invoked, effectively letting
Spring Integration coerce a class into behaving like an implementation of a MessageSource . In this
example, you'll build a MessageSource , which is very succinct:
package org.springframework.integration.message;
import org.springframework.integration.core.Message;
public interface MessageSource<T> {
Message<T> receive();
}
In the example, you're building a solution that can pull status updates and return them in a simple
POJO object called Tweet .
package com.apress.springenterpriserecipes.springintegration.twitter;
import java.io.Serializable;
import java.util.Date;
// …
Search WWH ::




Custom Search