2016-02-19 273 views
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++; 
    } 
} 

回答

1

,你正在做a_numThreads = 50然後Executors.newFixedThreadPool(a_numThreads);是事實,意味着你不能在任何時間點與執行者創造更多的50個線程至少不會。

什麼文件的意思是,一個分區只能分配給1流,如果你不是創建50流創建51流後者將什麼也得不到的解釋here