3

I am trying to write application for real time processing with apache storm , kafka and trident but in initialization of TridentKafkaConfig i see this error

Exception in thread "main" java.lang.NoClassDefFoundError: kafka/api/OffsetRequest
at storm.kafka.KafkaConfig.<init>(KafkaConfig.java:43)
at storm.kafka.trident.TridentKafkaConfig.<init>(TridentKafkaConfig.java:30)
at spout.TestSpout.<clinit>(TestSpout.java:22)
at IOTTridentTopology.initializeTridentTopology(IOTTridentTopology.java:31)
at IOTTridentTopology.main(IOTTridentTopology.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: kafka.api.OffsetRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 10 more

my spout class is

public class TestSpout extends OpaqueTridentKafkaSpout {

private static TridentKafkaConfig config;
private static BrokerHosts HOSTS = new ZkHosts(TridentConfig.ZKHOSTS);
private static String TOPIC = "test";
private static int BUFFER_SIZE = TridentConfig.BUFFER_SIZE;

static{
    config = new TridentKafkaConfig(HOSTS, TOPIC);
    config.scheme = new SchemeAsMultiScheme(new RawScheme());
    config.bufferSizeBytes = BUFFER_SIZE;
}

public TestSpout(TridentKafkaConfig config) {
    super(config);
}

public TestSpout() {
    super(config);
}
}

main class:

 public static void main(String[] args) {
    initializeTridentTopology();
}

private static void initializeTridentTopology() {
    TridentTopology topology = new TridentTopology();
    TestSpout spout = new TestSpout();
    //////////////// test  //////////////////////

    topology.newStream("testspout", spout).each(spout.getOutputFields(), new TestFunction(), new Fields());

    ///////////////  end test ///////////////////

    LocalCluster cluster = new LocalCluster();

    Config config = new Config();
    config.setDebug(false);
    config.setMaxTaskParallelism(1);
    config.registerSerialization(storm.kafka.trident.GlobalPartitionInformation.class);
    config.registerSerialization(java.util.TreeMap.class);
    config.setNumWorkers(5);

    config.setFallBackOnJavaSerialization(true);

    cluster.submitTopology("KafkaTrident", config, topology.build());

}

and my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>IOT</groupId>
<artifactId>ver0.1</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>


    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-core</artifactId>
        <version>0.9.3</version>
    </dependency>


    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-kafka</artifactId>
        <version>0.9.3</version>
    </dependency>



</dependencies>

I am trying different version of storm-kafka (0.9.3 and 0.9.4 and 0.9.5 and 0.9.6 and 0.10.0) and storm-core (9.3 and 9.4 and 9.6)

But I still see my previous error

by googling i found this link but ...

ClassNotFoundException: kafka.api.OffsetRequest

4

2 回答 2

4

经过一番谷歌搜索后,我找到了这个链接 https://github.com/wurstmeister/storm-kafka-0.8-plus-test 并在 pom.xml 文件中找到了我的答案

通过添加此代码并找到兼容的 kafka 版本,所有问题都已解决

 <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_2.11</artifactId>
        <version>0.9.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
于 2016-01-06T11:01:46.383 回答
2

如果您使用 LocalCluster 部署风暴拓扑,则需要将 Kafka 库添加到您的依赖项中(对于 Storm 0.10.0):

    <dependency>
       <groupId>org.apache.kafka</groupId>
       <artifactId>kafka_2.9.2</artifactId>
       <version>0.8.1.1</version>
     </dependency>

错过了kafka.api.OffsetRequest类,因为org.apache.kafka为storm-kafka 提供了依赖项:http: //mvnrepository.com/artifact/org.apache.storm/storm-kafka/0.10.0。有关详细信息,请参阅提供的依赖项部分。

于 2016-01-06T08:07:26.457 回答