本文整理匯總了Java中kafka.javaapi.consumer.SimpleConsumer.host方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleConsumer.host方法的具體用法?Java SimpleConsumer.host怎麽用?Java SimpleConsumer.host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kafka.javaapi.consumer.SimpleConsumer
的用法示例。
在下文中一共展示了SimpleConsumer.host方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: brokerInfo
import kafka.javaapi.consumer.SimpleConsumer; //導入方法依賴的package包/類
public List<BrokerInfo> brokerInfo() {
List<BrokerInfo> binfos = new ArrayList<BrokerInfo>();
Set<Integer> bids = consumerMap.keySet();
BrokerInfo binfo = null;
SimpleConsumer consumer = null;
for (int bid : bids) {
consumer = consumerMap.get(bid);
binfo = new BrokerInfo(bid, consumer.host(), consumer.port());
binfos.add(binfo);
}
return binfos;
}
示例2: fetchMessages
import kafka.javaapi.consumer.SimpleConsumer; //導入方法依賴的package包/類
public ByteBufferMessageSet fetchMessages(int partition, long offset) throws IOException {
String topic = config.topic;
FetchRequest req = new FetchRequestBuilder().clientId(config.clientId).addFetch(topic, partition, offset, config.fetchMaxBytes)
.maxWait(config.fetchWaitMaxMs).build();
FetchResponse fetchResponse = null;
SimpleConsumer simpleConsumer = null;
try {
simpleConsumer = findLeaderConsumer(partition);
if (simpleConsumer == null) {
// LOG.error(message);
return null;
}
fetchResponse = simpleConsumer.fetch(req);
} catch (Exception e) {
if (e instanceof ConnectException || e instanceof SocketTimeoutException || e instanceof IOException
|| e instanceof UnresolvedAddressException) {
LOG.warn("Network error when fetching messages:", e);
if (simpleConsumer != null) {
String host = simpleConsumer.host();
int port = simpleConsumer.port();
simpleConsumer = null;
throw new KafkaException("Network error when fetching messages: " + host + ":" + port + " , " + e.getMessage(), e);
}
} else {
throw new RuntimeException(e);
}
}
if (fetchResponse.hasError()) {
short code = fetchResponse.errorCode(topic, partition);
if (code == ErrorMapping.OffsetOutOfRangeCode() && config.resetOffsetIfOutOfRange) {
long startOffset = getOffset(topic, partition, config.startOffsetTime);
offset = startOffset;
}
if(leaderBroker != null) {
LOG.error("fetch data from kafka topic[" + config.topic + "] host[" + leaderBroker.host() + ":" + leaderBroker.port() + "] partition["
+ partition + "] error:" + code);
}else {
}
return null;
} else {
ByteBufferMessageSet msgs = fetchResponse.messageSet(topic, partition);
return msgs;
}
}