hbcStreaming API 的 Java 客戶端
hbc (Hosebird Client)是Twitter Streaming API 的 Java 客戶端開發(fā)包。
主要特性:
-
支持GZip、OAuth和分塊(partitioning);
-
自動重新連接,并進(jìn)行適當(dāng)?shù)腷ackfill計(jì)數(shù);
-
訪問原始字節(jié)的有效負(fù)載;
-
適時(shí)重新分配,并進(jìn)行相關(guān)統(tǒng)計(jì)。
包含了2個(gè)主要模塊:
-
hbc-core:該模塊使用了一個(gè)簡單的消息隊(duì)列,用戶可以輪詢消息。
-
hbc-twitter4j:該模塊允許開發(fā)者在消息隊(duì)列中使用Twitter4J項(xiàng)目和它的數(shù)據(jù)模型,以提供一個(gè)分析層。
示例代碼:
ClientBuilder builder = new ClientBuilder()
.name("Hosebird-Client-01") // optional: mainly for the logs
.hosts(hosebirdHosts)
.authentication(hosebirdAuth)
.endpoint(hosebirdEndpoint)
.processor(new StringDelimitedProcessor(msgQueue))
.eventMessageQueue(eventQueue); // optional: use this if you want to process client events
Client hosebirdClient = builder.build();
// Attempts to establish a connection.
hosebirdClient.connect();
// on a different thread, or multiple different threads....
while (!client.isDone()) {
String msg = msgQueue.take();
something(msg);
profit();
}
hosebirdClient.shutdown();
評論
圖片
表情
