我从互联网借用代码创建了一个从远程kafka集群读取数据的风暴喷口。我检查了风暴集群和kafka集群之间的连接,这没关系。我可以通过kafka命令行工具阅读主题。但是当我提交拓扑时,它的喷口不会发出任何东西。请帮忙!!
public class KafkaTopology {
public static void main(String[] args) throws Exception {
List<String> hosts = new ArrayList<String>();
hosts.add("10.87.36.80:2181");
// SpoutConfig kafkaConf = new SpoutConfig(StaticHosts.fromHostString(hosts, 3), "test", "/kafkastorm", "discovery");
SpoutConfig kafkaConf = new SpoutConfig(new ZkHosts("localhost:2181"),
"test", // Kafka topic to read from
"/test", // Root path in Zookeeper for the spout to store consumer offsets
"clickdata"); // ID for storing consumer offsets in Zookeeper
kafkaConf.scheme = new SchemeAsMultiScheme(new StringScheme());
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConf);
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("spout", kafkaSpout, 2);
builder.setBolt("printer", new PrinterBolt())
.shuffleGrouping("spout");
Config config = new Config();
config.setDebug(true);
if(args!=null && args.length > 0) {
config.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], config, builder.createTopology());
} else {
config.setMaxTaskParallelism(3);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("kafka", config, builder.createTopology());
Thread.sleep(10000);
cluster.shutdown();
}
}
}
答案 0 :(得分:0)
hosts.add("10.87.36.80:2181");
这应该是Kafka经纪人的地址,端口2181
通常由Zookeepers使用。