从Kafka topic中获取数据并在Storm中进行分析

从Kafka topic中获取数据

    String zks = "x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181";

    String topic = "test";
    String zkRoot = "/storm";
    String id = "word";//默认是word
    BrokerHosts brokerHosts = new ZkHosts(zks);

    /**
     *  1、Spout属性设置
     */
    SpoutConfig spoutConf = new SpoutConfig(brokerHosts, topic, zkRoot, "KafkaSpout-reader");
    spoutConf.scheme = new SchemeAsMultiScheme(new StringScheme());
    spoutConf.forceFromStart = false;//强制不从最开始读取数据
    spoutConf.zkServers = Arrays.asList(new String[] {"x.x.x.x","x.x.x.x","x.x.x.x"});
    spoutConf.zkPort = 2181;
    spoutConf.scheme = new SchemeAsMultiScheme(new StringScheme());
    spoutConf.startOffsetTime =kafka.api.OffsetRequest.LatestTime();
    spoutConf.fetchMaxWait = 10000000;

    /** 
     *  2、创建TopologyBuilder 
     *  并设置Spout对象(其中KafkaSpout对象来自storm-kafka-0.9.2-incubating.jar包下
     *  public class storm.kafka.KafkaSpout extends backtype.storm.topology.base.BaseRichSpout)
     */
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("KafkaSpout-reader", new KafkaSpout(spoutConf), 1);//spoutConf中可以进行SpoutConfig属性设置
    builder.setBolt("xxx", new KafkaBolt(), 3).shuffleGrouping("KafkaSpout-reader");
将获取的数据提交的Storm中处理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值