Search in sources :

Example 1 with RandomNumberGeneratorSpout

use of org.apache.storm.starter.spout.RandomNumberGeneratorSpout in project jstorm by alibaba.

the class TridentMinMaxOfDevicesTopology method buildDevicesTopology.

/**
     * Creates a topology with device-id and count (which are whole numbers) as
     * tuple fields in a stream and it finally generates result stream based on
     * min amd max with device-id and count values.
     */
public static StormTopology buildDevicesTopology() {
    String deviceID = "device-id";
    String count = "count";
    Fields allFields = new Fields(deviceID, count);
    RandomNumberGeneratorSpout spout = new RandomNumberGeneratorSpout(allFields, 10, 1000);
    TridentTopology topology = new TridentTopology();
    Stream devicesStream = topology.newStream("devicegen-spout", spout).each(allFields, new Debug("##### devices"));
    devicesStream.minBy(deviceID).each(allFields, new Debug("#### device with min id"));
    devicesStream.maxBy(count).each(allFields, new Debug("#### device with max count"));
    return topology.build();
}
Also used : Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Stream(storm.trident.Stream) RandomNumberGeneratorSpout(org.apache.storm.starter.spout.RandomNumberGeneratorSpout) Debug(storm.trident.operation.builtin.Debug)

Example 2 with RandomNumberGeneratorSpout

use of org.apache.storm.starter.spout.RandomNumberGeneratorSpout in project storm by apache.

the class TridentMinMaxOfDevicesTopology method buildDevicesTopology.

/**
     * Creates a topology with device-id and count (which are whole numbers) as tuple fields in a stream and it finally
     * generates result stream based on min amd max with device-id and count values.
     */
public static StormTopology buildDevicesTopology() {
    String deviceID = "device-id";
    String count = "count";
    Fields allFields = new Fields(deviceID, count);
    RandomNumberGeneratorSpout spout = new RandomNumberGeneratorSpout(allFields, 10, 1000);
    TridentTopology topology = new TridentTopology();
    Stream devicesStream = topology.newStream("devicegen-spout", spout).each(allFields, new Debug("##### devices"));
    devicesStream.minBy(deviceID).each(allFields, new Debug("#### device with min id"));
    devicesStream.maxBy(count).each(allFields, new Debug("#### device with max count"));
    return topology.build();
}
Also used : Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) RandomNumberGeneratorSpout(org.apache.storm.starter.spout.RandomNumberGeneratorSpout) Debug(org.apache.storm.trident.operation.builtin.Debug)

Aggregations

RandomNumberGeneratorSpout (org.apache.storm.starter.spout.RandomNumberGeneratorSpout)2 Fields (backtype.storm.tuple.Fields)1 Stream (org.apache.storm.trident.Stream)1 TridentTopology (org.apache.storm.trident.TridentTopology)1 Debug (org.apache.storm.trident.operation.builtin.Debug)1 Fields (org.apache.storm.tuple.Fields)1 Stream (storm.trident.Stream)1 TridentTopology (storm.trident.TridentTopology)1 Debug (storm.trident.operation.builtin.Debug)1