當前位置: 首頁>>代碼示例>>Java>>正文


Java TopologyBuilder類代碼示例

本文整理匯總了Java中org.apache.storm.topology.TopologyBuilder的典型用法代碼示例。如果您正苦於以下問題:Java TopologyBuilder類的具體用法?Java TopologyBuilder怎麽用?Java TopologyBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TopologyBuilder類屬於org.apache.storm.topology包,在下文中一共展示了TopologyBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String args[]) throws InterruptedException {
	Config config = new Config();
	config.setNumWorkers(3);
	TopologyBuilder topologyBuilder = new TopologyBuilder();
	
	String zkConnString = "localhost:2181";
	String topicName = "sensor-data";
	
	BrokerHosts hosts = new ZkHosts(zkConnString);
	SpoutConfig spoutConfig = new SpoutConfig(hosts, topicName , "/" + topicName, UUID.randomUUID().toString());
	spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());

	KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
	topologyBuilder.setSpout("spout", kafkaSpout, 1);
       topologyBuilder.setBolt("es-bolt", new ElasticSearchBolt(), 1).shuffleGrouping("spout");
       
       LocalCluster cluster = new LocalCluster();
       cluster.submitTopology("storm-es-example", config, topologyBuilder.createTopology());
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:20,代碼來源:SensorTopology.java

示例2: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String[] args) {
	Config config = new Config();
	config.setNumWorkers(3);
	TopologyBuilder topologyBuilder = new TopologyBuilder();
	
	String zkConnString = "localhost:2181";
	String topicName = "storm-diy";
	
	BrokerHosts hosts = new ZkHosts(zkConnString);
	SpoutConfig spoutConfig = new SpoutConfig(hosts, topicName , "/" + topicName, UUID.randomUUID().toString());
	spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());

	KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
	topologyBuilder.setSpout("spout", kafkaSpout, 1);
	topologyBuilder.setBolt("parser", new ParseAndUsageBolt(), 1).shuffleGrouping("spout");
	topologyBuilder.setBolt("usageCassandra", new UsageCassandraBolt("localhost", "usage"), 1).shuffleGrouping("parser", "usagestream");
	topologyBuilder.setBolt("tdrCassandra", new TDRCassandraBolt("localhost", "tdr"), 1).shuffleGrouping("parser", "tdrstream");
	
	LocalCluster cluster = new LocalCluster();
       cluster.submitTopology("storm-diy", config, topologyBuilder.createTopology());
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:22,代碼來源:TelecomProcessorTopology.java

示例3: buildTopology

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
private static TopologyBuilder buildTopology() throws Exception {
        TopologyBuilder builder = new TopologyBuilder();
        String topicName = Configuration.getConfig().getString("rtc.mq.spout.topic");
        String groupName = Configuration.getConfig().getString("rtc.mq.spout.group");
        BrokerHosts hosts = new ZkHosts(Configuration.getConfig().getString("rtc.zk.hosts"));
        SpoutConfig spoutConfig = new SpoutConfig(hosts, topicName, "/consumers", groupName);
        spoutConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime();
        spoutConfig.zkServers = Arrays.asList(Configuration.getConfig().getString("rtc.storm.zkServers").split(","));
        spoutConfig.zkPort = Configuration.getConfig().getInt("rtc.storm.zkPort");
        spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
        KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
        builder.setSpout("MQSpout", kafkaSpout, Configuration.getConfig().getInt("rtc.storm.spout.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.spout.task"));
        builder.setBolt("ExtractBolt", new ExtractBolt(), Configuration.getConfig().getInt("rtc.storm.extract.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.extract.bolt.task")).shuffleGrouping("MQSpout");
        builder.setBolt("Statistic", new StatisticBolt(), Configuration.getConfig().getInt("rtc.storm.statistic.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.statistic.bolt.task")).fieldsGrouping("ExtractBolt", new Fields(new String[]{"hashKeys"}));
//        builder.setBolt("Alarm", new AlarmBolt(), Configuration.getConfig().getInt("rtc.storm.alarm.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.alarm.bolt.task")).fieldsGrouping("Statistic", new Fields(new String[]{"EventName"}));
        return builder;
    }
 
開發者ID:JiuzhouSec,項目名稱:nightwatch,代碼行數:18,代碼來源:SingleTopology.java

示例4: buildTopology

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
private static TopologyBuilder buildTopology() throws Exception {
        TopologyBuilder builder = new TopologyBuilder();
        String topicName = Configuration.getConfig().getString("rtc.mq.spout.topic");
        String groupName = Configuration.getConfig().getString("rtc.mq.spout.group");
        BrokerHosts hosts = new ZkHosts(Configuration.getConfig().getString("rtc.zk.hosts"));
        SpoutConfig spoutConfig = new SpoutConfig(hosts, topicName, "/consumers", groupName);

        spoutConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime();
        spoutConfig.zkServers = Arrays.asList(Configuration.getConfig().getString("rtc.storm.zkServers").split(","));
        spoutConfig.zkPort = Configuration.getConfig().getInt("rtc.storm.zkPort");
        spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
        KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig);
        builder.setSpout("MQSpout", kafkaSpout, Configuration.getConfig().getInt("rtc.storm.spout.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.spout.task"));
        builder.setBolt("ExtractBolt", new ExtractBolt(), Configuration.getConfig().getInt("rtc.storm.extract.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.extract.bolt.task")).shuffleGrouping("MQSpout");
        builder.setBolt("Statistic", new StatisticBolt(), Configuration.getConfig().getInt("rtc.storm.statistic.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.statistic.bolt.task")).fieldsGrouping("ExtractBolt", new Fields(new String[]{"hashKeys"}));
//        builder.setBolt("Alarm", new AlarmBolt(), Configuration.getConfig().getInt("rtc.storm.alarm.bolt.parallelismHint")).setNumTasks(Configuration.getConfig().getInt("rtc.storm.alarm.bolt.task")).fieldsGrouping("Statistic", new Fields(new String[]{"EventName"}));
        return builder;
    }
 
開發者ID:JiuzhouSec,項目名稱:nightwatch,代碼行數:19,代碼來源:ClusterTopology.java

示例5: createTopology

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
@Override
public StormTopology createTopology() {
    final String topic = config.getKafkaSpeakerTopic();
    final String name = String.format("%s_%s_%d", getTopologyName(), topic, System.currentTimeMillis());
    final Integer parallelism = config.getParallelism();

    TopologyBuilder builder = new TopologyBuilder();

    String spoutId = "KafkaSpout-" + topic;
    builder.setSpout(spoutId, createKafkaSpout(topic, name), parallelism);
    LoggerBolt logger = new LoggerBolt()
            .withLevel(config.getLoggerLevel())
            .withWatermark(config.getLoggerWatermark());

    builder.setBolt("Logger", logger, parallelism)
            .shuffleGrouping(spoutId);

    return builder.createTopology();
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:20,代碼來源:KafkaLoggerTopology.java

示例6: createTopology

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
@Override
public StormTopology createTopology() {
    final String directory = config.getFilterDirectory();
    final String name = String.format("%s_%s_%s_%d", getTopologyName(), topic, directory, System.currentTimeMillis());

    String spoutId = "KafkaSpout-" + topic;
    int parallelism = 1;

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(spoutId, createKafkaSpout(topic, name), parallelism);
    filer = new FilerBolt().withFileName("utils-" + topic + ".log");
    if (directory.length() != 0)
        filer.withDir(new File(directory));

    builder.setBolt("utils", filer, parallelism)
            .shuffleGrouping(spoutId);
    return builder.createTopology();
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:19,代碼來源:KafkaFilerTopology.java

示例7: createCtrlBranch

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
protected void createCtrlBranch(TopologyBuilder builder, List<CtrlBoltRef> targets)
        throws StreamNameCollisionException {
    checkAndCreateTopic(config.getKafkaCtrlTopic());

    org.apache.storm.kafka.KafkaSpout kafkaSpout;
    kafkaSpout = createKafkaSpout(config.getKafkaCtrlTopic(), SPOUT_ID_CTRL);
    builder.setSpout(SPOUT_ID_CTRL, kafkaSpout);

    RouteBolt route = new RouteBolt(getTopologyName());
    builder.setBolt(BOLT_ID_CTRL_ROUTE, route)
            .shuffleGrouping(SPOUT_ID_CTRL);

    KafkaBolt kafkaBolt = createKafkaBolt(config.getKafkaCtrlTopic());
    BoltDeclarer outputSetup = builder.setBolt(BOLT_ID_CTRL_OUTPUT, kafkaBolt)
            .shuffleGrouping(BOLT_ID_CTRL_ROUTE, route.STREAM_ID_ERROR);

    for (CtrlBoltRef ref : targets) {
        String boltId = ref.getBoltId();
        ref.getDeclarer().allGrouping(BOLT_ID_CTRL_ROUTE, route.registerEndpoint(boltId));
        outputSetup.shuffleGrouping(boltId, ref.getBolt().getCtrlStreamId());
    }
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:23,代碼來源:AbstractTopology.java

示例8: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("integer", new RandomIntegerSpout(), 1);
    builder.setBolt("slidingsum", new SlidingWindowSumBolt().withWindow(new Count(30), new Count(10)), 1)
            .shuffleGrouping("integer");
    builder.setBolt("tumblingavg", new TumblingWindowAvgBolt().withTumblingWindow(new Count(3)), 1)
            .shuffleGrouping("slidingsum");
    builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("tumblingavg");
    Config conf = new Config();
    conf.setDebug(true);
    if (args != null && args.length > 0) {
        conf.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } else {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("test", conf, builder.createTopology());
        Utils.sleep(40000);
        cluster.killTopology("test");
        cluster.shutdown();
    }
}
 
開發者ID:bigdataFlySQL,項目名稱:SQLonStorm,代碼行數:22,代碼來源:SlidingWindowTopology.java

示例9: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String[] args) throws AlreadyAliveException,
		InvalidTopologyException {
	// create an instance of TopologyBuilder class
	TopologyBuilder builder = new TopologyBuilder();
	// set the spout class
	builder.setSpout("SampleSpout", new SampleSpout(), 2);
	// set the bolt class
	builder.setBolt("SampleBolt", new SampleBolt(), 4).shuffleGrouping(
			"SampleSpout");
	Config conf = new Config();
	conf.setNumWorkers(3);
	// This statement submit the topology on remote
	// args[0] = name of topology
	try {
		StormSubmitter.submitTopology(args[0], conf,
				builder.createTopology());
	} catch (AlreadyAliveException alreadyAliveException) {
		System.out.println(alreadyAliveException);
	} catch (InvalidTopologyException invalidTopologyException) {
		System.out.println(invalidTopologyException);
	} catch (AuthorizationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Apache-Storm,代碼行數:26,代碼來源:SampleStormClusterTopology.java

示例10: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();

    builder.setSpout("word", new WordSpout(), 1);
    builder.setBolt("exclaim", new ExclamationBolt(), 1).shuffleGrouping("word");   // Tuple流向:word 》 exclaim
    builder.setBolt("print", new PrintBolt(), 1).shuffleGrouping("exclaim");        // exclaim 》 print

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

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

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

        LocalCluster cluster = new LocalCluster();      // storm依賴,<scope>provided</scope>--> 本地開發是注釋掉 -->
        cluster.submitTopology("test3", conf, builder.createTopology());
        Utils.sleep(60 * 1000);
        cluster.killTopology("test3");
        cluster.shutdown();
    }
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:24,代碼來源:ExclamationTopology.java

示例11: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void main(String[] args){
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout(SPOUT_ID,new SentenceSpout());
    topologyBuilder.setBolt(BOLT_ID_SENTENCE_SPLIT,new SentenceSplitBolt()).shuffleGrouping(SPOUT_ID);
    topologyBuilder.setBolt(BOLT_ID_WORD_COUNT,new WordCountBlot()).fieldsGrouping(BOLT_ID_SENTENCE_SPLIT,new Fields("word"));
    topologyBuilder.setBolt(BOLT_ID_COUNT_REPORT,new WordsReportBolt()).globalGrouping(BOLT_ID_WORD_COUNT);

    Config config  = new Config();
    LocalCluster localCluster = new LocalCluster();

    localCluster.submitTopology(TOPOLOGY_ID,config,topologyBuilder.createTopology());
    //
    Utils.sleep(10000);
    localCluster.killTopology(TOPOLOGY_ID);
    localCluster.shutdown();
}
 
開發者ID:yangboz,項目名稱:SpringBootKafkaStorm,代碼行數:17,代碼來源:WordCountTopology.java

示例12: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
public static void  main(String[] args){
    args = new String[] {"localhost:2181", "storm-test-topic", "/brokers", "storm-consumer"};
    // Log program usages and exit if there are less than 4 command line arguments
    if(args.length < 4) {
        LOG.fatal("Incorrect number of arguments. Required arguments: <zk-hosts> <kafka-topic> <zk-path> <clientid>");
        System.exit(1);
    }
    // Build Spout configuration using input command line parameters
    final BrokerHosts zkrHosts = new ZkHosts(args[0]);
    final String kafkaTopic = args[1];
    final String zkRoot = args[2];
    final String clientId = args[3];
    final SpoutConfig spoutConfig = new SpoutConfig(zkrHosts,kafkaTopic,zkRoot,clientId);
    spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
    // Build topology to consume message from kafka and print them on console
    final TopologyBuilder topologyBuilder = new TopologyBuilder();
    // Build topology to consume message from kafka and print them on console
    topologyBuilder.setSpout("kafka-spout",new KafkaSpout(spoutConfig));
    //Route the output of Kafka Spout to Logger bolt to log messages consumed from Kafka
    topologyBuilder.setBolt("kafka-message",new LoggerBolt()).globalGrouping("kafka-spout");
    //Route the output of Kafka Spout to Logger bolt to log messages consumed from Kafka
    final LocalCluster localCluster = new LocalCluster();
    localCluster.submitTopology("kafka-toology",new Config(),topologyBuilder.createTopology());
}
 
開發者ID:yangboz,項目名稱:SpringBootKafkaStorm,代碼行數:25,代碼來源:LoggerTopology.java

示例13: main

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
/**
 * Main. Launches a remote Storm topology.
 * @param args The input args.
 * @throws Exception if any.
 */
public static void main(String[] args) throws Exception {
    OptionSet options = PARSER.parse(args);
    if (!options.hasOptions() || options.has(HELP_ARG) || !options.has(SPOUT_ARG)) {
        printHelp();
        return;
    }
    String spoutClass = (String) options.valueOf(SPOUT_ARG);
    List<String> arguments = (List<String>) options.valuesOf(ARGUMENT_ARG);
    Integer parallelism = (Integer) options.valueOf(PARALLELISM_ARG);
    Double cpuLoad = (Double) options.valueOf(CPU_LOAD_ARG);
    Double onHeapMemoryLoad = (Double) options.valueOf(ON_HEAP_MEMORY_LOAD_ARG);
    Double offHeapMemoryLoad = (Double) options.valueOf(OFF_HEAP_MEMORY_LOAD_ARG);
    String configuration = (String) options.valueOf(CONFIGURATION_ARG);

    BulletStormConfig bulletStormConfig = new BulletStormConfig(configuration);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(TopologyConstants.RECORD_COMPONENT, getSpout(spoutClass, arguments), parallelism)
           .setCPULoad(cpuLoad)
           .setMemoryLoad(onHeapMemoryLoad, offHeapMemoryLoad);
    log.info("Added spout " + spoutClass + " with parallelism " + parallelism + ", CPU load " + cpuLoad +
             ", On-heap memory " + onHeapMemoryLoad + ", Off-heap memory " + offHeapMemoryLoad);

    submit(bulletStormConfig, TopologyConstants.RECORD_COMPONENT, builder);
}
 
開發者ID:yahoo,項目名稱:bullet-storm,代碼行數:30,代碼來源:Topology.java

示例14: getSpeedTopolgy

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
/**
 * @return the topology to run
 */
protected StormTopology getSpeedTopolgy() {
    final TopologyBuilder tp = new TopologyBuilder();

    // consume from the truck_speed_events topic
    tp.setSpout("kafka_spout", new KafkaSpout<>(getKafkaSpoutConfig()), 1);

    // parse pipe-delimited speed events into a POJO
    tp.setBolt("parse_speed_event", new ParseSpeedEventBolt())
            .shuffleGrouping("kafka_spout");

    // calculate the average speed for driver-route over a 10 second window
    tp.setBolt("average_speed", new AverageSpeedBolt().withTumblingWindow(new BaseWindowedBolt.Duration(WINDOW_SIZE_MS, TimeUnit.MILLISECONDS)))
            .shuffleGrouping("parse_speed_event");
                    //new Fields(ParseSpeedEventBolt.FIELD_DRIVER_ID, ParseSpeedEventBolt.FIELD_ROUTE_ID));

    // send results back to Kafka results topic
    tp.setBolt("kakfa_bolt", getKafkaBolt())
            .shuffleGrouping("average_speed");

    return tp.createTopology();
}
 
開發者ID:bbende,項目名稱:hdf-trucking-app,代碼行數:25,代碼來源:SpeedTopology.java

示例15: getActionTopology

import org.apache.storm.topology.TopologyBuilder; //導入依賴的package包/類
protected StormTopology getActionTopology(String zkhost) {
    BrokerHosts hosts = new ZkHosts(zkhost);
    TopologyBuilder builder = new TopologyBuilder();
    // trigger spouts setting
    SpoutConfig triggerConfig = new SpoutConfig(hosts, TOPICS[3], "/" + TOPICS[3], UUID.randomUUID().toString());
    triggerConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
    triggerConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime();
    triggerConfig.ignoreZkOffsets = true;
    // status spouts setting
    SpoutConfig statusConfig = new SpoutConfig(hosts, TOPICS[4], "/" + TOPICS[4], UUID.randomUUID().toString());
    statusConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
    statusConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime();
    statusConfig.ignoreZkOffsets = true;
    // Set spouts
    builder.setSpout("trigger-spout", new KafkaSpout(triggerConfig));
    builder.setSpout("status-spout", new KafkaSpout(statusConfig));
    /* Set bolts */
    builder.setBolt("scheduling-bolt", new SchedulingBolt())
            .shuffleGrouping("trigger-spout");
    builder.setBolt("status-bolt", new StatusBolt(), 4)
            .shuffleGrouping("status-spout");
    builder.setBolt("execute-code-bolt", new ExecutingBolt()).fieldsGrouping("scheduling-bolt",new Fields("roadMapId"));
    builder.setBolt("provisioning-bolt", new ProvisioningBolt()).fieldsGrouping("execute-code-bolt",new Fields("roadMapId"));
    builder.setBolt("calling-feed-bolt", new CallingFeedBolt()).fieldsGrouping("provisioning-bolt",new Fields("roadMapId"));
    return builder.createTopology();
}
 
開發者ID:ENOW-IJI,項目名稱:ENOW-server,代碼行數:27,代碼來源:DockerSubmitter.java


注:本文中的org.apache.storm.topology.TopologyBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。