资源简介

Storm+Kafka+Flume+Zookeeper+MySQL实现数据实时分析(程序案例篇)源代码

资源截图

代码片段和文件信息

package com.lyz.storm;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.generated.StormTopology;
import org.apache.storm.kafka.KafkaSpout;
import org.apache.storm.kafka.SpoutConfig;
import org.apache.storm.kafka.ZkHosts;
import org.apache.storm.topology.TopologyBuilder;

import com.lyz.storm.bolt.MySplitBolt;
import com.lyz.storm.bolt.MyWordCountAndPrintBolt;

/**
 * 这个Driver使Kafka、strom、mysql进行串联起来。
 *
 * 这个代码执行前需要创建kafka的topic创建代码如下:
 * [root@liuyazhuang kafka]# bin/kafka-topics.sh --create --zookeeper liuyazhuang1:2181 --replication-factor 1 -partitions 3 --topic wordCount
 *
 * 接着还要向kafka中传递数据,打开一个shell的producer来模拟生产数据
 * [root@liuyazhuang kafka]# bin/kafka-console-producer.sh --broker-list liuyazhuang:9092 --topic wordCount
 * 接着输入数据
 *
 * @author liuyazhuang
 */
public class StormTopologyDriver {

    public static void main(String[] args) throws Exception {
        //1、准备任务信息
        TopologyBuilder topologyBuilder = new TopologyBuilder();
        SpoutConfig spoutConfig = new SpoutConfig(new ZkHosts(“192.168.209.121:2181“)“wordCount““/wordCount““wordCount“);
topologyBuilder.setSpout(“KafkaSpout“new KafkaSpout(spoutConfig)2);
        topologyBuilder.setBolt(“bolt1“new MySplitBolt()4).shuffleGrouping(“KafkaSpout“);
        topologyBuilder.setBolt(“bolt2“new MyWordCountAndPrintBolt()2).shuffleGrouping(“bolt1“);

        //2、任务提交
        Config config = new Config();
        config.setNumWorkers(2);
        StormTopology stormTopology = topologyBuilder.createTopology();
        
        if(args != null && args.length > 0){
         StormSubmitter.submitTopology(args[0] config topologyBuilder.createTopology());
        }else{
            //本地模式
            LocalCluster localCluster = new LocalCluster();
            localCluster.submitTopology(“wordcount“configstormTopology);
        }
        
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-04 23:45  storm-kafka-mysql\
     文件        1437  2018-02-24 17:09  storm-kafka-mysql\.classpath
     文件        1434  2018-02-24 13:45  storm-kafka-mysql\.project
     目录           0  2018-03-04 23:45  storm-kafka-mysql\.settings\
     文件         575  2015-07-23 14:04  storm-kafka-mysql\.settings\.jsdtscope
     文件         736  2018-02-24 17:05  storm-kafka-mysql\.settings\org.eclipse.jdt.core.prefs
     文件          90  2015-07-23 14:04  storm-kafka-mysql\.settings\org.eclipse.m2e.core.prefs
     文件        1908  2018-02-24 13:45  storm-kafka-mysql\.settings\org.eclipse.wst.common.component
     文件         252  2018-02-24 17:09  storm-kafka-mysql\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2015-07-23 14:04  storm-kafka-mysql\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2015-07-23 14:04  storm-kafka-mysql\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件          50  2015-07-23 14:04  storm-kafka-mysql\.settings\org.eclipse.wst.validation.prefs
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456363\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456363\1024\
     文件         116  2018-02-24 15:12  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456363\1024\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456363\1027\
     文件         116  2018-02-24 15:12  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456363\1027\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456510\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456510\1024\
     文件         116  2018-02-24 15:15  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456510\1024\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456510\1027\
     文件         116  2018-02-24 15:15  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456510\1027\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456788\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456788\1024\
     文件         116  2018-02-24 15:19  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456788\1024\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456788\1027\
     文件         116  2018-02-24 15:19  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456788\1027\worker.yaml
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456930\
     目录           0  2018-03-04 23:45  storm-kafka-mysql\logs\workers-artifacts\wordcount-1-1519456930\1024\
............此处省略100个文件信息

评论

共有 条评论