Implementing GraphTupleProcessor

In order to populate the graph database with relationships gleaned from Twitter status messages, we need to implement the GraphTupleProcessor interface. The following code illustrates parsing the Twitter status message's JSON object and creating "user" and "hashtag" vertices with "mentions" relationships.

TweetGraphTupleProcessor.java public class TweetGraphTupleProcessor implements GraphTupleProcessor { @Override public void process(Graph g, TridentTuple tuple, TridentCollector collector) { Long timestamp = tuple.getLong(0); JSONObject json = (JSONObject)tuple.get(1); Vertex user = findOrCreateUser(g, (String)json.get("user"), (String)json.get("name")); JSONArray hashtags = (JSONArray)json.get("hashtags"); for(int ...

Get Storm Blueprints: Patterns for Distributed Real-time Computation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.