完成迭代后,调用不会出现在while循环中

时间:2016-03-11 05:24:47

标签: java apache-kafka

我有Apache kafka使用者的示例代码

public class WorkerThread implements Callable<Object> {
    ConsumerConnector consumerConnector;
    private static ArrayList<Object> list = new ArrayList<>();

    @Override
    public Object call() throws Exception {
        processMsg();
        return list;
    }

    private void processMsg() {
        StringMessage msg = new StringMessage();
        Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
        topicCountMap.put(KafkaConstants.LOB_TOPIC, new Integer(1));
        Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumerConnector
                .createMessageStreams(topicCountMap);
        KafkaStream<byte[], byte[]> stream = consumerMap.get(KafkaConstants.LOB_TOPIC).get(0);
        ConsumerIterator<byte[], byte[]> itr = stream.iterator();

            while (itr.hasNext()) {
                msg.setMessage(new String((itr.next().message())));
                list.add(msg);
                System.out.println("&&&" + msg);
            }

        System.out.println("++++++++++++");
    }
}

在上面的示例中,我的"++++++" sysout无效..任何人都知道原因..?

1 个答案:

答案 0 :(得分:0)