apache flink kafka streaming exception java.lang.ClassNotFoundException:kafka.javaapi.consumer.SimpleConsumer

时间:2015-10-25 13:06:01

标签: apache-kafka apache-flink

尝试运行Apache Flink kafka流示例并获取异常 -

java.lang.NoClassDefFoundError: kafka/javaapi/consumer/SimpleConsumer
    at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer.getPartitionsForTopic(FlinkKafkaConsumer.java:607)
    at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer.<init>(FlinkKafkaConsumer.java:280)
    at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer082.<init>(FlinkKafkaConsumer082.java:49)
    at org.apache.flink.streaming.examples.kafka.ReadStreamingFromKafka.main(ReadStreamingFromKafka.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:497)
    at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:395)
    at org.apache.flink.client.program.Client.runBlocking(Client.java:252)
    at org.apache.flink.client.CliFrontend.executeProgramBlocking(CliFrontend.java:670)
    at org.apache.flink.client.CliFrontend.run(CliFrontend.java:325)
    at org.apache.flink.client.CliFrontend.parseParameters(CliFrontend.java:971)
    at org.apache.flink.client.CliFrontend.main(CliFrontend.java:1021)
Caused by: java.lang.ClassNotFoundException: kafka.javaapi.consumer.SimpleConsumer
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 15 more

我写了一个非常基本的例子 -

            StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
            Properties properties = new Properties();
            properties.setProperty("bootstrap.servers", "localhost:9092");
            properties.setProperty("zookeeper.connect", "localhost:2181");
            properties.setProperty("group.id", "test");

            DataStream<String> messageStream = env.addSource(new FlinkKafkaConsumer082<>("topic", new SimpleStringSchema(),properties));
            messageStream.print();

0 个答案:

没有答案