Error producing to embedded kafka queue after upgrade from 0.7 to 0.8.1.1

北城余情 提交于 2019-12-06 12:06:25

It turns out this has to do with the Time parameter in the new KafkaServer constructor.

I was passing in a null param for the kafka.utils.Time object:

private KafkaServer server = new KafkaServer(config, null);

Instead, you need to create an implementation of the kafka.utils.Time interface, and pass in a new instance of that:

private KafkaServer server = new KafkaServer(config, new SystemTime());

private static class SystemTime implements Time {

    @Override
    public long milliseconds() {
        return System.currentTimeMillis();
    }

    @Override
    public long nanoseconds() {
        return System.nanoTime();
    }

    @Override
    public void sleep(long arg0) {
        try {
            Thread.sleep(arg0);
        } catch (InterruptedException e) {
            log.error("Kafka systemtime interrupted",e);
        }
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!