当前位置: 首页>>代码示例>>Java>>正文


Java RandomSentenceSpout类代码示例

本文整理汇总了Java中org.apache.storm.starter.spout.RandomSentenceSpout的典型用法代码示例。如果您正苦于以下问题:Java RandomSentenceSpout类的具体用法?Java RandomSentenceSpout怎么用?Java RandomSentenceSpout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RandomSentenceSpout类属于org.apache.storm.starter.spout包,在下文中一共展示了RandomSentenceSpout类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import org.apache.storm.starter.spout.RandomSentenceSpout; //导入依赖的package包/类
public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    
    builder.setSpout("spout", new RandomSentenceSpout(), 5);
    
    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));
    
    Config conf = new Config();
    conf.setDebug(true);
    
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    
    try {
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60,
                new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:24,代码来源:WordCountTopology.java

示例2: buildProducerTopology

import org.apache.storm.starter.spout.RandomSentenceSpout; //导入依赖的package包/类
/**
 * A topology that produces random sentences using {@link RandomSentenceSpout} and
 * publishes the sentences using a KafkaBolt to kafka "test" topic.
 *
 * @return the storm topology
 */
public StormTopology buildProducerTopology(Properties prop) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new RandomSentenceSpout(), 2);
    /**
     * The output field of the RandomSentenceSpout ("word") is provided as the boltMessageField
     * so that this gets written out as the message in the kafka topic.
     */
    KafkaBolt bolt = new KafkaBolt().withProducerProperties(prop)
            .withTopicSelector(new DefaultTopicSelector("test"))
            .withTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper("key", "word"));
    builder.setBolt("forwardToKafka", bolt, 1).shuffleGrouping("spout");
    return builder.createTopology();
}
 
开发者ID:ziyunhx,项目名称:storm-net-adapter,代码行数:20,代码来源:TridentKafkaWordCount.java

示例3: main

import org.apache.storm.starter.spout.RandomSentenceSpout; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

    TopologyBuilder builder = new TopologyBuilder();

    builder.setSpout("spout", new RandomSentenceSpout(), 5);

    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));

    Config conf = new Config();
    conf.setDebug(true);

    if (args != null && args.length > 0) {
      conf.setNumWorkers(3);

      StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    }
    else {
      conf.setMaxTaskParallelism(3);

      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("word-count", conf, builder.createTopology());

      Thread.sleep(10000);

      cluster.shutdown();
    }
  }
 
开发者ID:ziyunhx,项目名称:storm-net-adapter,代码行数:29,代码来源:WordCountTopology.java


注:本文中的org.apache.storm.starter.spout.RandomSentenceSpout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。