0
我看到這個便條卡夫卡消費文檔中 -卡夫卡消費者 - Java客戶端
因爲有許多的分區,這還是平衡了許多 消費者的情況下的負載。不過請注意,不能有比分區更多的實例。
我有50個分區爲單個主題。如果我將a_numThreads值設置爲50,則從每個分區中獲取1條消息?上述消息是否意味着我無法在任何時候創建超過50個線程?
public void run(int a_numThreads) {
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(topic, new Integer(a_numThreads));
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(topic);
// now launch all the threads
//
executor = Executors.newFixedThreadPool(a_numThreads);
// now create an object to consume the messages
//
int threadNumber = 0;
for (final KafkaStream stream : streams) {
executor.submit(new ConsumerTest(stream, threadNumber));
threadNumber++;
}
}