use of com.twitter.hbc.core.processor.HosebirdMessageProcessor in project flink by apache.
the class TwitterSource method run.
@Override
public void run(final SourceContext<String> ctx) throws Exception {
LOG.info("Initializing Twitter Streaming API connection");
StreamingEndpoint endpoint = initializer.createEndpoint();
Authentication auth = new OAuth1(properties.getProperty(CONSUMER_KEY), properties.getProperty(CONSUMER_SECRET), properties.getProperty(TOKEN), properties.getProperty(TOKEN_SECRET));
client = new ClientBuilder().name(properties.getProperty(CLIENT_NAME, "flink-twitter-source")).hosts(properties.getProperty(CLIENT_HOSTS, Constants.STREAM_HOST)).endpoint(endpoint).authentication(auth).processor(new HosebirdMessageProcessor() {
public DelimitedStreamReader reader;
@Override
public void setup(InputStream input) {
reader = new DelimitedStreamReader(input, Constants.DEFAULT_CHARSET, Integer.parseInt(properties.getProperty(CLIENT_BUFFER_SIZE, "50000")));
}
@Override
public boolean process() throws IOException, InterruptedException {
String line = reader.readLine();
ctx.collect(line);
return true;
}
}).build();
client.connect();
running = true;
LOG.info("Twitter Streaming API connection established successfully");
// just wait now
while (running) {
synchronized (waitLock) {
waitLock.wait(100L);
}
}
}
Aggregations