storm

来源:互联网 发布:淘宝店导航在线制作 编辑:程序博客网 时间:2024/04/29 06:03

遇到的问题

maven缺少依赖,下不了jar包
在网上找了篇博客

修改 Maven 的配置文件(安装目录下的 conf/settings.xml 文件),将 <mirrors>..</mirrors> 间的内容改为:

  1. <mirrors>
  2. <!-- mirror | Specifies a repository mirror site to use instead of a given
  3. repository. The repository that | this mirror serves has an ID that matches
  4. the mirrorOf element of this mirror. IDs are used | for inheritance and direct
  5. lookup purposes, and must be unique across the set of mirrors. | -->
  6. <mirror>
  7. <id>nexus-osc</id>
  8. <mirrorOf>central</mirrorOf>
  9. <name>Nexus osc</name>
  10. <url>http://maven.oschina.net/content/groups/public/</url>
  11. </mirror>
  12. <mirror>
  13. <id>nexus-osc-thirdparty</id>
  14. <mirrorOf>thirdparty</mirrorOf>
  15. <name>Nexus osc thirdparty</name>
  16. <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
  17. </mirror>
  18. </mirrors>
XML

以及将 <profile>...<profile> 之间的内容改为:

  1. <profile>
  2. <id>jdk-1.4</id>
  3.  
  4. <activation>
  5. <jdk>1.4</jdk>
  6. </activation>
  7.  
  8. <repositories>
  9. <repository>
  10. <id>nexus</id>
  11. <name>local private nexus</name>
  12. <url>http://maven.oschina.net/content/groups/public/</url>
  13. <releases>
  14. <enabled>true</enabled>
  15. </releases>
  16. <snapshots>
  17. <enabled>false</enabled>
  18. </snapshots>
  19. </repository>
  20. </repositories>
  21. <pluginRepositories>
  22. <pluginRepository>
  23. <id>nexus</id>
  24. <name>local private nexus</name>
  25. <url>http://maven.oschina.net/content/groups/public/</url>
  26. <releases>
  27. <enabled>true</enabled>
  28. </releases>
  29. <snapshots>
  30. <enabled>false</enabled>
  31. </snapshots>
  32. </pluginRepository>
  33. </pluginRepositories>
  34. </profile>
XML

改好后保存,再次执行 maven ... 应该就可以了。


第一个小程序,数字累加

public class StormDemo {
    /**
     * 创建spout
     * @author Administrator
     *
     */
    public static class MySpout extends BaseRichSpout{
        Map conf;
        TopologyContext context;
        SpoutOutputCollector collector;
        
        int i;
        //这是一个死循环,会不停的被调用
        public void nextTuple() {
            this.collector.emit(new Values(i++));
            
            
        }
        /**
         * 初始化方法,只会被执行一次,在这里面可以执行一些初始化的操作
         * Map conf  配置类,tolplogy的配置信息
         * TopologyContext context  tolplogy的上下文
         * SpoutOutputCollector collector 发射器,向外发射数据
         */
        public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
            this.conf = conf;
            this.context = context;
            this.collector = collector;
            
        }
        //声明输出字段,给发送出去的数据相应的起个名字
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
            declarer.declare(new Fields("num"));
            
        }
        
    }
    
    public static class MyBolt extends BaseRichBolt{
        
        Map stormConf;
        TopologyContext context;
        OutputCollector collector;
        
        int sum;
        //会被循环调用,只要spout发送一个tuple,这边就会被调用一次
        public void execute(Tuple input) {
            Integer value = input.getIntegerByField("num");
            sum += value;
            System.out.println("sum="+sum);
            
        }
        
        public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
            this.stormConf = stormConf;
            this.context = context;
            this.collector = collector;
            
        }
        //只有spout中的nexttuple或者bolt中的execute中执行了emit发射功能,才需要在这里声明输出字段
        public void declareOutputFields(OutputFieldsDeclarer arg0) {
            
            
        }
        
    }
    
    public static void main(String[] args) {
        TopologyBuilder topologyBuilder = new TopologyBuilder();
        topologyBuilder.setSpout("aa", new MySpout());
        topologyBuilder.setBolt("bb", new MyBolt()).shuffleGrouping("aa");
        //创建一个本地集群来运行topology任务
        LocalCluster localCluster = new LocalCluster();
        localCluster.submitTopology("localTopology", new Config(), topologyBuilder.createTopology());
    }
}




0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 绿萝叶子尖干枯怎么办 养的花叶子干了怎么办 云株花叶子发黄怎么办 驱蚊草叶子发黄怎么办 多肉叶子有黑点怎么办 多肉植物干瘪了怎么办 多肉叶片有黑点怎么办 多肉叶片有黑斑怎么办 多肉表面有黑点怎么办 杉果游戏买了后怎么办 盆景叶子上的灰怎么办 福建茶盆景掉叶怎么办 被普通蜘蛛咬了怎么办 被小蜘蛛咬了怎么办 被一般蜘蛛咬了怎么办 联通4g流量超出怎么办 腿上的肥胖纹怎么办除 金属眼镜腿歪了怎么办 炸东西油往外溢怎么办 油反复使用起沫怎么办 炸东西的油黑了怎么办 板栗放久了干了怎么办 三四个月的宝宝拉肚子怎么办 四个月的孩子拉肚子怎么办 4个月孩子拉肚子怎么办 三阳的房子很热怎么办 买了缺角的房子怎么办 多肉摇钱树焉了怎么办 虎皮兰叶子烂了怎么办 三角龙骨烂根了怎么办 地板木龙骨会动怎么办 多肉植物开花后怎么办 春峰之辉烂了怎么办 仙人指不开花是怎么办 大门开在破财位怎么办 人走霉运的时候怎么办 pp助手刷机失败怎么办 别人骂我很难听怎么办 被骂了心里不爽怎么办 被别人扎小人了怎么办 人要倒霉的时候怎么办