java 使用 Kafka Spout 的 Kafka Storm 集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17342454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Kafka Storm Integration using Kafka Spout
提问by Yavar
I am using KafkaSpout. Please find the test program below.
我正在使用 KafkaSpout。请在下面找到测试程序。
I am using Storm 0.8.1. Multischeme class is there in Storm 0.8.2. I will be using that. I just want to know how were the earlier versions working just by instantiating the StringScheme() class? Where can I download earlier versions of Kafka Spout? But I doubt that would be a correct alternative than to work on Storm 0.8.2. ??? (Confused)
我正在使用 Storm 0.8.1。Storm 0.8.2 中有 Multischeme 类。我会用那个。我只想通过实例化 StringScheme() 类知道早期版本是如何工作的?哪里可以下载较早版本的 Kafka Spout?但我怀疑这是否比在 Storm 0.8.2 上工作更正确。???(使困惑)
When I run the code (given below) on storm cluster (i.e. when I push my topology) I get the following error (This happens when the Scheme part is commented else of course I will get compiler error as the class is not there in 0.8.1):
当我在 Storm 集群上运行代码(下面给出)时(即当我推送我的拓扑时)我收到以下错误(这发生在对 Scheme 部分进行注释时,否则当然我会得到编译器错误,因为该类在 0.8 中不存在.1):
java.lang.NoClassDefFoundError: backtype/storm/spout/MultiScheme
at storm.kafka.TestTopology.main(TestTopology.java:37)
Caused by: java.lang.ClassNotFoundException: backtype.storm.spout.MultiScheme
In the code given below you may find the spoutConfig.scheme=new StringScheme(); part commented. I was getting compiler error if I don't comment that line which is but natural as there are no constructors in there. Also when I instantiate MultiScheme I get error as I dont have that class in 0.8.1.
在下面给出的代码中,您可能会发现 spoutConfig.scheme=new StringScheme(); 部分评论。如果我不注释该行,我会收到编译器错误,这很自然,因为那里没有构造函数。此外,当我实例化 MultiScheme 时,我收到错误,因为我在 0.8.1 中没有那个类。
public class TestTopology {
public static class PrinterBolt extends BaseBasicBolt {
public void declareOutputFields(OutputFieldsDeclarer declarer) {
}
public void execute(Tuple tuple, BasicOutputCollector collector) {
System.out.println(tuple.toString());
}
}
public static void main(String [] args) throws Exception {
List<HostPort> hosts = new ArrayList<HostPort>();
hosts.add(new HostPort("127.0.0.1",9092));
LocalCluster cluster = new LocalCluster();
TopologyBuilder builder = new TopologyBuilder();
SpoutConfig spoutConfig = new SpoutConfig(new KafkaConfig.StaticHosts(hosts, 1), "test", "/zkRootStorm", "STORM-ID");
spoutConfig.zkServers=ImmutableList.of("localhost");
spoutConfig.zkPort=2181;
//spoutConfig.scheme=new StringScheme();
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
builder.setSpout("spout",new KafkaSpout(spoutConfig));
builder.setBolt("printer", new PrinterBolt())
.shuffleGrouping("spout");
Config config = new Config();
cluster.submitTopology("kafka-test", config, builder.createTopology());
Thread.sleep(600000);
}
回答by Chris Bedford
I had the same problem. Finally resolved it, and I put the complete running example up on github.
我有同样的问题。终于解决了,我把完整的运行例子放到了github上。
You are welcome to check it out here > https://github.com/buildlackey/cep
欢迎您在这里查看 > https://github.com/buildlackey/cep
(click on the storm+kafka directory for a sample program that should get you up and running).
(单击storm+kafka 目录以获取应该让您启动并运行的示例程序)。
回答by Rimmon
We had a similar issue.
我们有一个类似的问题。
Our solution:
我们的解决方案:
Open pom.xml
Change scope from provided to
<scope>compile</scope>
打开 pom.xml
将范围从提供到
<scope>compile</scope>
If you want to know more about dependency scopes check the maven docu: Maven docu - dependency scopes
如果您想了解有关依赖范围的更多信息,请查看 Maven 文档: Maven 文档 - 依赖范围