Created
March 18, 2013 13:36
-
-
Save moaikids/5187169 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.LinkedBlockingQueue; | |
import com.twitter.hbc.ClientBuilder; | |
import com.twitter.hbc.core.Client; | |
import com.twitter.hbc.core.Constants; | |
import com.twitter.hbc.core.HttpHosts; | |
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; | |
import com.twitter.hbc.core.event.Event; | |
import com.twitter.hbc.core.processor.StringDelimitedProcessor; | |
import com.twitter.hbc.httpclient.auth.OAuth1; | |
/** | |
* Hello twitter world! | |
*/ | |
public class App { | |
String consumerKey = ""; | |
String consumerSecret = ""; | |
String authToken = ""; | |
String authSecret = ""; | |
public static void main(String[] args) { | |
new App().doit(); | |
} | |
public void doit() { | |
BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100000); | |
BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(1000); | |
// client | |
ClientBuilder builder = new ClientBuilder() | |
.name("hbc test client") | |
.hosts(new HttpHosts(Constants.STREAM_HOST)) | |
.authentication( | |
new OAuth1(consumerKey, consumerSecret, authToken, authSecret)) | |
.endpoint(new StatusesSampleEndpoint()) | |
.processor(new StringDelimitedProcessor(msgQueue)) | |
.eventMessageQueue(eventQueue) | |
.connectionTimeout(15000) | |
.socketTimeout(15000) | |
.gzipEnabled(true) | |
.retries(3); | |
Client client = builder.build(); | |
client.connect(); | |
while (!client.isDone()) { | |
try { | |
String msg = msgQueue.take(); | |
System.out.println(msg); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment