0

I use the twitter4j query interface to filter tweets http://twitter4j.org/javadoc/twitter4j/Query.html. But the twitter spout in https://github.com/nathanmarz/storm-starter/blob/master/src/jvm/storm/starter/spout/TwitterSampleSpout.java:43 uses queue.offer(status). I don't have a reference to Status, how do I integrate these API(s) to process live tweets.

Joe
  • 14,513
  • 28
  • 82
  • 144

1 Answers1

0

This is what we have been using successfully to filter tweets:

public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;
    StatusListener listener = new StatusListener() {

        public void onStatus(Status status) {
            queue.offer(status);
        }

        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        public void onTrackLimitationNotice(int i) {
        }

        public void onScrubGeo(long l, long l1) {
        }

        public void onException(Exception e) {
        }

    };
    TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
    _twitterStream = fact.getInstance();
    _twitterStream.addListener(listener);
    _twitterStream.filter(new FilterQuery().track(TERMS_TO_TRACK).setIncludeEntities(true));
}
kunal
  • 123
  • 3
  • 10
  • We don't use the streaming API, since we filter tweets based on range of dates and a host of other criteria which is available only on the Query API interface. Hence my original question on how to integrate, if I don't have access to the Status object – Joe Jan 21 '13 at 08:45
  • You can have status object just parsing the Tuple object in bolts execute() method like so: `Status status = (Status) tuple.getValue(0);` – Orbita Jul 04 '13 at 11:06