Search in sources :

Example 1 with DefaultKafkaConsumerFactory

use of org.apache.heron.spouts.kafka.DefaultKafkaConsumerFactory in project heron by twitter.

the class HeronKafkaSpoutSampleTopology method main.

public static void main(String[] args) {
    Map<String, Object> kafkaConsumerConfig = new HashMap<>();
    kafkaConsumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    kafkaConsumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "sample-kafka-spout");
    kafkaConsumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
    kafkaConsumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
    LOG.info("Kafka Consumer Config: {}", kafkaConsumerConfig);
    KafkaConsumerFactory<String, String> kafkaConsumerFactory = new DefaultKafkaConsumerFactory<>(kafkaConsumerConfig);
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    topologyBuilder.setSpout(KAFKA_SPOUT_NAME, new KafkaSpout<>(kafkaConsumerFactory, Collections.singletonList("test-topic")));
    topologyBuilder.setBolt(LOGGING_BOLT_NAME, new LoggingBolt()).shuffleGrouping(KAFKA_SPOUT_NAME);
    Config config = new Config();
    config.setNumStmgrs(1);
    config.setContainerCpuRequested(1);
    config.setContainerRamRequested(ByteAmount.fromGigabytes(1));
    config.setContainerDiskRequested(ByteAmount.fromGigabytes(1));
    config.setComponentCpu(KAFKA_SPOUT_NAME, 0.25);
    config.setComponentRam(KAFKA_SPOUT_NAME, ByteAmount.fromMegabytes(256));
    config.setComponentDisk(KAFKA_SPOUT_NAME, ByteAmount.fromMegabytes(512));
    config.setComponentCpu(LOGGING_BOLT_NAME, 0.25);
    config.setComponentRam(LOGGING_BOLT_NAME, ByteAmount.fromMegabytes(256));
    config.setComponentDisk(LOGGING_BOLT_NAME, ByteAmount.fromMegabytes(256));
    Simulator simulator = new Simulator();
    simulator.submitTopology("heron-kafka-spout-sample-topology", config, topologyBuilder.createTopology());
}
Also used : HashMap(java.util.HashMap) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.heron.api.Config) DefaultKafkaConsumerFactory(org.apache.heron.spouts.kafka.DefaultKafkaConsumerFactory) Simulator(org.apache.heron.simulator.Simulator)

Aggregations

HashMap (java.util.HashMap)1 Config (org.apache.heron.api.Config)1 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)1 Simulator (org.apache.heron.simulator.Simulator)1 DefaultKafkaConsumerFactory (org.apache.heron.spouts.kafka.DefaultKafkaConsumerFactory)1 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)1