當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleConsumer.host方法代碼示例

本文整理匯總了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;

}
 
開發者ID:chickling,項目名稱:kmanager,代碼行數:14,代碼來源:OffsetGetter.java

示例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;
        }
    }
 
開發者ID:zhangjunfang,項目名稱:jstorm-0.9.6.3-,代碼行數:48,代碼來源:KafkaConsumer.java


注:本文中的kafka.javaapi.consumer.SimpleConsumer.host方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。