Kafka流NoClassDefFoundError ByteBufferInputStream

时间:2018-04-05 16:48:39

标签: apache-kafka apache-kafka-streams

我正在尝试以下Kafka流示例代码。 http://kafka.apache.org/0110/documentation/streams/tutorial

import java.io.*;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import org.json.JSONObject;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.KStreamBuilder;

@WebServlet("/KafkaStreamsTest")
public class KafkaStreamsTest extends HttpServlet {

    /**
     *
     */
    private final String topic = "testtopic";
    private final String streamouttopic = "streamtesttopic";
    public static final String CLIENT_ID = "SampleStreamProducer";
    JSONObject jsonObject;

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    }

    // Do the same thing for GET and POST requests
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

        System.out.println("Server called");

        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost");
        props.put("group.id", CLIENT_ID);
        props.put(StreamsConfig.APPLICATION_ID_CONFIG, CLIENT_ID);

        props.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
        props.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());

        KStreamBuilder builder = new KStreamBuilder();
        builder.stream(topic).to(streamouttopic);

        final KafkaStreams streams = new KafkaStreams(builder, props);
        final CountDownLatch latch = new CountDownLatch(1);

        // attach shutdown handler to catch control-c
        Runtime.getRuntime().addShutdownHook(new Thread("streams-shutdown-hook") {
            @Override
            public void run() {
                streams.close();
                latch.countDown();
            }
        });

        try {
        streams.start();
        latch.await();
        } catch (Throwable e) {
        System.exit(1);
        }
        System.exit(0);   
    }
}

当我运行时,我收到错误

Exception in thread "StreamThread-1" java.lang.NoClassDefFoundError: org/apache/kafka/common/record/ByteBufferInputStream

有人可以指导我的原因是什么?我有kafka-clients-0.11.0.0-cp1.jar,kafka-streams-0.10.0.0.jar以及此Eclipse项目中包含的其他必需的JAR文件。

0 个答案:

没有答案