我使用twitter4j查询接口过滤tweet http://twitter4j.org/javadoc/twitter4j/Query.html。但是https://github.com/nathanmarz/storm-starter/blob/master/src/jvm/storm/starter/spout/TwitterSampleSpout.java:43中的twitter喷口使用了queue.offer(status)。我没有参考状态,我如何集成这些API(s)来处理实时tweet。
这是我们成功使用的tweet过滤方法:
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));
}