Package backtype.storm.topology

Examples of backtype.storm.topology.TopologyBuilder


        System.out.println("DONE");
    }

    @Override
    protected StormTopology createTopology() {
        TopologyBuilder builder = new TopologyBuilder();
        IRichSpout feedSpout =
                new ExternalFeedToKafkaAdapterSpout(
                        new TestFeedItemProvider(),
                        BROKER_CONNECT_STRING,
                        getTopicName(), null);
        builder.setSpout("externalFeedSpout", feedSpout);
        builder.setSpout("kafkaSpout", createKafkaSpout());
        VerboseCollectorBolt bolt = new VerboseCollectorBolt(5);
        builder.setBolt("collector", bolt).shuffleGrouping("kafkaSpout");

        return builder.createTopology();
    }
View Full Code Here


    queueSpout.setJmsProvider(jmsQueueProvider);
    queueSpout.setJmsTupleProducer(producer);
    queueSpout.setJmsAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    queueSpout.setDistributed(true); // allow multiple instances

    TopologyBuilder builder = new TopologyBuilder();
   
    // spout with 5 parallel instances
    builder.setSpout(JMS_QUEUE_SPOUT, queueSpout, 5);

    // intermediate bolt, subscribes to jms spout, anchors on tuples, and auto-acks
    builder.setBolt(INTERMEDIATE_BOLT,
        new GenericBolt("INTERMEDIATE_BOLT", true, true, new Fields("json")), 3).shuffleGrouping(
        JMS_QUEUE_SPOUT);

    // bolt that subscribes to the intermediate bolt, and auto-acks
    // messages.
    builder.setBolt(FINAL_BOLT, new GenericBolt("FINAL_BOLT", true, true), 3).shuffleGrouping(
        INTERMEDIATE_BOLT);
   
    // bolt that subscribes to the intermediate bolt, and publishes to a JMS Topic   
    JmsBolt jmsBolt = new JmsBolt();
    jmsBolt.setJmsProvider(jmsTopicProvider);
   
    // anonymous message producer just calls toString() on the tuple to create a jms message
    jmsBolt.setJmsMessageProducer(new JmsMessageProducer() {
      @Override
      public Message toMessage(Session session, Tuple input) throws JMSException{
        System.out.println("Sending JMS Message:" + input.toString());
        TextMessage tm = session.createTextMessage(input.toString());
        return tm;
      }
    });
   
    builder.setBolt(JMS_TOPIC_BOLT, jmsBolt).shuffleGrouping(INTERMEDIATE_BOLT);
   
    // JMS Topic spout
    JmsSpout topicSpout = new JmsSpout();
    topicSpout.setJmsProvider(jmsTopicProvider);
    topicSpout.setJmsTupleProducer(producer);
    topicSpout.setJmsAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    topicSpout.setDistributed(false);
   
    builder.setSpout(JMS_TOPIC_SPOUT, topicSpout);
   
    builder.setBolt(ANOTHER_BOLT, new GenericBolt("ANOTHER_BOLT", true, true), 1).shuffleGrouping(
        JMS_TOPIC_SPOUT);

    Config conf = new Config();

    if (args.length > 0) {
      conf.setNumWorkers(3);

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

      conf.setDebug(true);

      LocalCluster cluster = new LocalCluster();
      cluster.submitTopology("storm-jms-example", conf, builder.createTopology());
      Utils.sleep(60000);
      cluster.killTopology("storm-jms-example");
      cluster.shutdown();
    }
  }
View Full Code Here

        }
    }


    public static void main(String[] args) {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("spout",
            new MetaSpout(initMetaConfig(), new ConsumerConfig("storm-spout"), new StringScheme()), 10);
        builder.setBolt("bolt", new FailEveryOther()).shuffleGrouping("spout");

        Config conf = new Config();
        // Set the consume topic
        conf.put(MetaSpout.TOPIC, "neta-test");
        // Set the max buffer size in bytes to fetch messages.
        conf.put(MetaSpout.FETCH_MAX_SIZE, 1024 * 1024);

        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("test", conf, builder.createTopology());
    }
View Full Code Here

    return new BoltDeclarerImpl(component);
  }

  public TopologyBuilder buildTopologyBuilder() {
    String coordinator = _spoutId + "/coordinator";
    TopologyBuilder builder = new TopologyBuilder();
    SpoutDeclarer declarer = builder.setSpout(coordinator,
        new TransactionalSpoutCoordinator(_spout));
    for (Map conf : _spoutConfs) {
      declarer.addConfigurations(conf);
    }
    declarer.addConfiguration(Config.TOPOLOGY_TRANSACTIONAL_ID, _id);

    BoltDeclarer emitterDeclarer = builder
        .setBolt(
            _spoutId,
            new CoordinatedBolt(
                new TransactionalSpoutBatchExecutor(_spout),
                null, null), _spoutParallelism)
        .allGrouping(
            coordinator,
            TransactionalSpoutCoordinator.TRANSACTION_BATCH_STREAM_ID)
        .addConfiguration(Config.TOPOLOGY_TRANSACTIONAL_ID, _id);
    if (_spout instanceof ICommitterTransactionalSpout) {
      emitterDeclarer.allGrouping(coordinator,
          TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID);
    }
    for (String id : _bolts.keySet()) {
      Component component = _bolts.get(id);
      Map<String, SourceArgs> coordinatedArgs = new HashMap<String, SourceArgs>();
      // get all source component
      for (String c : componentBoltSubscriptions(component)) {
        coordinatedArgs.put(c, SourceArgs.all());
      }

      IdStreamSpec idSpec = null;
      if (component.committer) {
        idSpec = IdStreamSpec
            .makeDetectSpec(
                coordinator,
                TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID);
      }
      BoltDeclarer input = builder.setBolt(id, new CoordinatedBolt(
          component.bolt, coordinatedArgs, idSpec),
          component.parallelism);
      for (Map conf : component.componentConfs) {
        input.addConfigurations(conf);
      }
View Full Code Here

    return topologyBuilder.getTopologyBuilder();
  }

  public static void SetLocalTopology() throws Exception {
    TopologyBuilder builder = SetBuilder();

    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology(topologyName, conf, builder.createTopology());

    Thread.sleep(600000);

    cluster.shutdown();
  }
View Full Code Here

  }

  public static void SetRemoteTopology() throws AlreadyAliveException,
      InvalidTopologyException, TopologyAssignException {

    TopologyBuilder builder = SetBuilder();

    StormSubmitter.submitTopology(topologyName, conf,
        builder.createTopology());

  }
View Full Code Here

    conf.put(Config.TOPOLOGY_WORKERS, workerNum);

  }

  public static void SetLocalTopology() throws Exception {
    TopologyBuilder builder = new TopologyBuilder();

    conf.put(TOPOLOGY_BOLT_PARALLELISM_HINT, Integer.valueOf(1));

    SetBuilder(builder, conf);

    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("SplitMerge", conf, builder.createTopology());

    Thread.sleep(60000);

    cluster.shutdown();
  }
View Full Code Here

    String streamName = (String) conf.get(Config.TOPOLOGY_NAME);
    if (streamName == null) {
      streamName = "SequenceTest";
    }

    TopologyBuilder builder = new TopologyBuilder();

    SetBuilder(builder, conf);

    conf.put(Config.STORM_CLUSTER_MODE, "distributed");

    StormSubmitter.submitTopology(streamName, conf,
        builder.createTopology());

  }
View Full Code Here

    }
  }
  public StormTopology buildTopology()
  {
    Config conf = getConf();
    TopologyBuilder builder = new TopologyBuilder();

    int spout_Parallelism_hint = JStormUtils.parseInt(
        conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1);
    int bolt_Parallelism_hint = JStormUtils.parseInt(
        conf.get(TOPOLOGY_BOLT_PARALLELISM_HINT), 2);

    builder.setSpout(SequenceTopologyDef.SEQUENCE_SPOUT_NAME,
        new SequenceSpout(), spout_Parallelism_hint);

    boolean isEnableSplit = JStormUtils.parseBoolean(
        conf.get("enable.split"), false);

    if (isEnableSplit == false) {
      builder.setBolt(SequenceTopologyDef.TOTAL_BOLT_NAME,
          new TotalCount(), bolt_Parallelism_hint).localFirstGrouping(
          SequenceTopologyDef.SEQUENCE_SPOUT_NAME);
    } else {

      builder.setBolt(SequenceTopologyDef.SPLIT_BOLT_NAME,
          new SplitRecord(), bolt_Parallelism_hint)
          .localOrShuffleGrouping(
              SequenceTopologyDef.SEQUENCE_SPOUT_NAME);

      builder.setBolt(SequenceTopologyDef.TRADE_BOLT_NAME,
          new PairCount(), bolt_Parallelism_hint).shuffleGrouping(
          SequenceTopologyDef.SPLIT_BOLT_NAME,
          SequenceTopologyDef.TRADE_STREAM_ID);
      builder.setBolt(SequenceTopologyDef.CUSTOMER_BOLT_NAME,
          new PairCount(), bolt_Parallelism_hint).shuffleGrouping(
          SequenceTopologyDef.SPLIT_BOLT_NAME,
          SequenceTopologyDef.CUSTOMER_STREAM_ID);

      builder.setBolt(SequenceTopologyDef.MERGE_BOLT_NAME,
          new MergeRecord(), bolt_Parallelism_hint)
          .fieldsGrouping(SequenceTopologyDef.TRADE_BOLT_NAME,
              new Fields("ID"))
          .fieldsGrouping(SequenceTopologyDef.CUSTOMER_BOLT_NAME,
              new Fields("ID"));

      builder.setBolt(SequenceTopologyDef.TOTAL_BOLT_NAME,
          new TotalCount(), bolt_Parallelism_hint).noneGrouping(
          SequenceTopologyDef.MERGE_BOLT_NAME);
    }

    boolean kryoEnable = JStormUtils.parseBoolean(conf.get("kryo.enable"),
        false);
    if (kryoEnable == true) {
      System.out.println("Use Kryo ");
      boolean useJavaSer = JStormUtils.parseBoolean(
          conf.get("fall.back.on.java.serialization"), true);

      Config.setFallBackOnJavaSerialization(conf, useJavaSer);

      Config.registerSerialization(conf, TradeCustomer.class);
      Config.registerSerialization(conf, Pair.class);
    }
    int ackerNum = JStormUtils.parseInt(
        conf.get(Config.TOPOLOGY_ACKER_EXECUTORS), 1);
    Config.setNumAckers(conf, ackerNum);

    int workerNum = JStormUtils.parseInt(conf.get(Config.TOPOLOGY_WORKERS),
        20);
    conf.put(Config.TOPOLOGY_WORKERS, workerNum);

    return  builder.createTopology()
 
View Full Code Here

      System.exit(-1);
    }

    LoadConf(args[0]);

    TopologyBuilder builder = setupBuilder();

    submitTopology(builder);

  }
View Full Code Here

TOP

Related Classes of backtype.storm.topology.TopologyBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.