Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created December 18, 2018 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/c97359d43d9c70de511766d70cce6a18 to your computer and use it in GitHub Desktop.
Save abhirockzz/c97359d43d9c70de511766d70cce6a18 to your computer and use it in GitHub Desktop.
@Override
public void onStatus(Status status) {
List<String> matchedTerms = new ArrayList<>(getMatchedTerms(status.getText()));
if (!status.isPossiblySensitive() && !matchedTerms.isEmpty()) {
String tweetID = String.valueOf(status.getId());
String tweetText = status.getText();
System.out.println("Matched terms - " + matchedTerms);
System.out.println("sending tweet to kafka...");
producer.send(new ProducerRecord<>(TWEETS_TOPIC, tweetID, tweetText),
new Callback() {
@Override
public void onCompletion(RecordMetadata metadata, Exception exception) {
System.out.println("Successfully sent tweet with ID " + tweetID + " and text '" + tweetText + "' to topic " + TWEETS_TOPIC);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment