Search in sources :

Example 26 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class TypedTupleExample method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    /**
         * The spout emits sequences of (Integer, Long, Long). TupleValueMapper can be used to extract fields
         * from the values and produce a stream of typed tuple (Tuple3<Integer, Long, Long> in this case.
         */
    Stream<Tuple3<Integer, Long, Long>> stream = builder.newStream(new RandomIntegerSpout(), TupleValueMappers.of(0, 1, 2));
    PairStream<Long, Integer> pairs = stream.mapToPair(t -> Pair.of(t._2 / 10000, t._1));
    pairs.window(TumblingWindows.of(Count.of(10))).groupByKey().print();
    Config config = new Config();
    if (args.length > 0) {
        config.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
            Utils.sleep(60_000);
        }
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) Tuple3(org.apache.storm.streams.tuple.Tuple3) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 27 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class WordCountToBolt method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // Redis config parameters for the RedisStoreBolt
    JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost("127.0.0.1").setPort(6379).build();
    // Storm tuple to redis key-value mapper
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    // The redis bolt (sink)
    IRichBolt redisStoreBolt = new RedisStoreBolt(poolConfig, storeMapper);
    // A stream of words
    builder.newStream(new TestWordSpout(), new ValueMapper<String>(0)).mapToPair(w -> Pair.of(w, 1)).countByKey().to(redisStoreBolt);
    Config config = new Config();
    if (args.length > 0) {
        config.setNumWorkers(1);
        StormSubmitter.submitTopologyWithProgressBar(args[0], config, builder.build());
    } else {
        try (LocalCluster cluster = new LocalCluster();
            LocalCluster.LocalTopology topo = cluster.submitTopology("test", config, builder.build())) {
            Utils.sleep(60_000);
        }
    }
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) LocalCluster(org.apache.storm.LocalCluster) RedisStoreBolt(org.apache.storm.redis.bolt.RedisStoreBolt) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Config(org.apache.storm.Config) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) TestWordSpout(org.apache.storm.testing.TestWordSpout) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 28 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class TridentMapExample method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    conf.setMaxSpoutPending(20);
    if (args.length == 0) {
        try (LocalDRPC drpc = new LocalDRPC();
            LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("wordCounter", conf, buildTopology(drpc))) {
            for (int i = 0; i < 100; i++) {
                System.out.println("DRPC RESULT: " + drpc.execute("words", "CAT THE DOG JUMPED"));
                Thread.sleep(1000);
            }
        }
    } else {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, buildTopology(null));
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) LocalDRPC(org.apache.storm.LocalDRPC) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 29 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class TridentMinMaxOfDevicesTopology method main.

public static void main(String[] args) throws Exception {
    StormTopology topology = buildDevicesTopology();
    Config conf = new Config();
    conf.setMaxSpoutPending(20);
    if (args.length == 0) {
        try (LocalCluster cluster = new LocalCluster();
            LocalTopology topo = cluster.submitTopology("devices-topology", conf, topology)) {
            Utils.sleep(60 * 1000);
        }
        System.exit(0);
    } else {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar("devices-topology", conf, topology);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 30 with LocalCluster

use of org.apache.storm.LocalCluster in project storm by apache.

the class KafkaSpoutTopologyMainNamedTopics method submitTopologyLocalCluster.

protected void submitTopologyLocalCluster(StormTopology topology, Config config) throws Exception {
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("test", config, topology);
    stopWaitingForInput();
}
Also used : LocalCluster(org.apache.storm.LocalCluster)

Aggregations

LocalCluster (org.apache.storm.LocalCluster)76 Config (org.apache.storm.Config)70 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)52 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)28 Fields (org.apache.storm.tuple.Fields)22 Map (java.util.Map)14 StreamBuilder (org.apache.storm.streams.StreamBuilder)9 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)7 HashMap (java.util.HashMap)6 LocalDRPC (org.apache.storm.LocalDRPC)6 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)6 TestWordSpout (org.apache.storm.testing.TestWordSpout)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 StormSubmitter (org.apache.storm.StormSubmitter)4 StormTopology (org.apache.storm.generated.StormTopology)4 ValueMapper (org.apache.storm.streams.operations.mappers.ValueMapper)4 TopologyContext (org.apache.storm.task.TopologyContext)4 Utils (org.apache.storm.utils.Utils)4 Yaml (org.yaml.snakeyaml.Yaml)4