Search in sources :

Example 1 with ProcessingGuarantee

use of org.apache.storm.kafka.spout.KafkaSpoutConfig.ProcessingGuarantee in project storm by apache.

the class KafkaClientSpoutNullBoltTopo method getTopology.

/**
 * Create and configure the topology.
 */
public static StormTopology getTopology(Map<String, Object> config) {
    final int spoutNum = Helper.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM);
    final int boltNum = Helper.getInt(config, BOLT_NUM, DEFAULT_BOLT_NUM);
    // 1 -  Setup Kafka Spout   --------
    String bootstrapServers = Optional.ofNullable(Helper.getStr(config, BOOTSTRAP_SERVERS)).orElse("127.0.0.1:9092");
    String kafkaTopic = Optional.ofNullable(Helper.getStr(config, KAFKA_TOPIC)).orElse("storm-perf-null-bolt-topic");
    ProcessingGuarantee processingGuarantee = ProcessingGuarantee.valueOf(Optional.ofNullable(Helper.getStr(config, PROCESSING_GUARANTEE)).orElse(ProcessingGuarantee.AT_LEAST_ONCE.name()));
    int offsetCommitPeriodMs = Helper.getInt(config, OFFSET_COMMIT_PERIOD_MS, 30_000);
    KafkaSpoutConfig<String, String> kafkaSpoutConfig = KafkaSpoutConfig.builder(bootstrapServers, kafkaTopic).setProcessingGuarantee(processingGuarantee).setOffsetCommitPeriodMs(offsetCommitPeriodMs).setFirstPollOffsetStrategy(FirstPollOffsetStrategy.EARLIEST).setTupleTrackingEnforced(true).build();
    KafkaSpout<String, String> spout = new KafkaSpout<>(kafkaSpoutConfig);
    // 2 -   DevNull Bolt   --------
    DevNullBolt bolt = new DevNullBolt();
    // 3 - Setup Topology  --------
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(SPOUT_ID, spout, spoutNum);
    builder.setBolt(BOLT_ID, bolt, boltNum).localOrShuffleGrouping(SPOUT_ID);
    return builder.createTopology();
}
Also used : ProcessingGuarantee(org.apache.storm.kafka.spout.KafkaSpoutConfig.ProcessingGuarantee) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) DevNullBolt(org.apache.storm.perf.bolt.DevNullBolt) KafkaSpout(org.apache.storm.kafka.spout.KafkaSpout)

Aggregations

KafkaSpout (org.apache.storm.kafka.spout.KafkaSpout)1 ProcessingGuarantee (org.apache.storm.kafka.spout.KafkaSpoutConfig.ProcessingGuarantee)1 DevNullBolt (org.apache.storm.perf.bolt.DevNullBolt)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1