Search in sources :

Example 26 with Stream

use of org.apache.storm.trident.Stream in project storm by apache.

the class WordCountTrident method buildTopology.

public static StormTopology buildTopology(String nameserverAddr, String topic) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
    TopicSelector selector = new DefaultTopicSelector(topic);
    Properties properties = new Properties();
    properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);
    RocketMqState.Options options = new RocketMqState.Options().withMapper(mapper).withSelector(selector).withProperties(properties);
    StateFactory factory = new RocketMqStateFactory(options);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RocketMqStateUpdater(), new Fields());
    return topology.build();
}
Also used : FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) TopicSelector(org.apache.storm.rocketmq.common.selector.TopicSelector) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) Values(org.apache.storm.tuple.Values) Properties(java.util.Properties) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) RocketMqStateFactory(org.apache.storm.rocketmq.trident.state.RocketMqStateFactory) TupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.TupleToMessageMapper) FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) TridentTopology(org.apache.storm.trident.TridentTopology) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) Stream(org.apache.storm.trident.Stream) RocketMqStateUpdater(org.apache.storm.rocketmq.trident.state.RocketMqStateUpdater) RocketMqState(org.apache.storm.rocketmq.trident.state.RocketMqState) RocketMqStateFactory(org.apache.storm.rocketmq.trident.state.RocketMqStateFactory)

Example 27 with Stream

use of org.apache.storm.trident.Stream in project storm by apache.

the class SolrFieldsTridentTopology method getTopology.

@Override
protected StormTopology getTopology() throws IOException {
    final TridentTopology tridentTopology = new TridentTopology();
    final SolrFieldsSpout spout = new SolrFieldsSpout();
    final Stream stream = tridentTopology.newStream("SolrFieldsSpout", spout);
    SolrConfig solrConfig = getSolrConfig();
    final StateFactory solrStateFactory = new SolrStateFactory(solrConfig, getSolrMapper(solrConfig));
    stream.partitionPersist(solrStateFactory, spout.getOutputFields(), new SolrUpdater(), new Fields());
    return tridentTopology.build();
}
Also used : SolrConfig(org.apache.storm.solr.config.SolrConfig) StateFactory(org.apache.storm.trident.state.StateFactory) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) SolrFieldsSpout(org.apache.storm.solr.spout.SolrFieldsSpout)

Example 28 with Stream

use of org.apache.storm.trident.Stream in project storm by apache.

the class TridentHBaseWindowingStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowsStore) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(TumblingCountWindow.of(1000), windowsStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) CountAsAggregator(org.apache.storm.trident.testing.CountAsAggregator) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.trident.Stream) Split(org.apache.storm.trident.testing.Split) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 29 with Stream

use of org.apache.storm.trident.Stream in project storm by apache.

the class TridentMinMaxOfDevicesTopology method buildVehiclesTopology.

/**
 * Creates a topology which demonstrates min/max operations on tuples of stream which contain vehicle and driver fields
 * with values {@link TridentMinMaxOfDevicesTopology.Vehicle} and {@link TridentMinMaxOfDevicesTopology.Driver} respectively.
 */
public static StormTopology buildVehiclesTopology() {
    Fields driverField = new Fields(Driver.FIELD_NAME);
    Fields vehicleField = new Fields(Vehicle.FIELD_NAME);
    Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME);
    FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles"));
    Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField, new Debug("#### slowest vehicle"));
    Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField, new Debug("##### slowest driver"));
    vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle")).project(driverField).each(driverField, new Debug("##### fastest driver"));
    vehiclesStream.max(new EfficiencyComparator()).each(vehicleField, new Debug("#### efficient vehicle"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) Debug(org.apache.storm.trident.operation.builtin.Debug)

Example 30 with Stream

use of org.apache.storm.trident.Stream 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

Stream (org.apache.storm.trident.Stream)30 Fields (org.apache.storm.tuple.Fields)27 TridentTopology (org.apache.storm.trident.TridentTopology)25 TridentState (org.apache.storm.trident.TridentState)13 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)13 Values (org.apache.storm.tuple.Values)13 StateFactory (org.apache.storm.trident.state.StateFactory)12 RelNode (org.apache.calcite.rel.RelNode)4 Consumer (org.apache.storm.trident.operation.Consumer)4 Debug (org.apache.storm.trident.operation.builtin.Debug)4 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)4 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RexNode (org.apache.calcite.rex.RexNode)3 Config (org.apache.storm.Config)3 MapGet (org.apache.storm.trident.operation.builtin.MapGet)3 Sum (org.apache.storm.trident.operation.builtin.Sum)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2