Search in sources :

Example 1 with JoinBolt

use of org.apache.storm.bolt.JoinBolt in project storm by apache.

the class JoinBoltExample method main.

public static void main(String[] args) throws Exception {
    FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
    FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("genderSpout", genderSpout);
    builder.setSpout("ageSpout", ageSpout);
    // inner join of 'age' and 'gender' records on 'id' field
    JoinBolt joiner = new JoinBolt("genderSpout", "id").join("ageSpout", "id", "genderSpout").select("genderSpout:id,ageSpout:id,gender,age").withTumblingWindow(new BaseWindowedBolt.Duration(10, TimeUnit.SECONDS));
    builder.setBolt("joiner", joiner).fieldsGrouping("genderSpout", new Fields("id")).fieldsGrouping("ageSpout", new Fields("id"));
    builder.setBolt("printer", new PrinterBolt()).shuffleGrouping("joiner");
    Config conf = new Config();
    conf.setDebug(true);
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("join-example", conf, builder.createTopology());
    generateGenderData(genderSpout);
    generateAgeData(ageSpout);
    Utils.sleep(30000);
    cluster.shutdown();
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) JoinBolt(org.apache.storm.bolt.JoinBolt) FeederSpout(org.apache.storm.testing.FeederSpout) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt)

Aggregations

Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 JoinBolt (org.apache.storm.bolt.JoinBolt)1 PrinterBolt (org.apache.storm.starter.bolt.PrinterBolt)1 FeederSpout (org.apache.storm.testing.FeederSpout)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 BaseWindowedBolt (org.apache.storm.topology.base.BaseWindowedBolt)1 Fields (org.apache.storm.tuple.Fields)1