如何使用New Kafka Consumer API编写样本kafka spout?

时间:2016-09-27 11:43:23

标签: apache-kafka apache-storm producer-consumer kafka-consumer-api

喜欢storm-kafka-client,我使用的是storm-kafka-client,但是效果不好,而且写一个新的spout也不行。 谁能帮我写一个样本卡夫卡鲸鱼嘴。

1 个答案:

答案 0 :(得分:0)

定义Topology.java

import storm.kafka.BrokerHosts;
import storm.kafka.KafkaSpout;
import storm.kafka.SpoutConfig;
import storm.kafka.StringScheme;
import storm.kafka.ZkHosts;

public class Topology{
  public static void main(String[] args){
     TopologyBuilder builder = new TopologyBuilder();
     String zkHosts = StringUtils.join("127.0.0.1", ',');

        BrokerHosts hosts = new ZkHosts(zkHosts);
        SpoutConfig spoutConfig = new SpoutConfig(hosts, "kafkaTopic_name", "/kafkaTopic_name", "kafkaGroup_name");
        spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
        spoutConfig.forceFromStart = forceFromStart;
        builder.setSpout("events", new KafkaSpout(spoutConfig), 5).setNumTasks(5);
        //...
  }
}

基本上,您需要创建SpoutConfig才能创建kafkaSpout。