zoukankan      html  css  js  c++  java
  • Using KafkaBolt to write to a kafka topic

    https://community.hortonworks.com/questions/27187/using-kafkabolt-to-write-to-a-kafka-topic.html

    --------------------------------------------------------------------------------------------------------------

    I'm building a kafka and storm based streaming application based on the usecase:

    1. Application produces JSON message to a kafka topic

    2. Kafka storm spout ingests the message and does processing

    3. Produce output to another kafka topic using a storm bolt

    Here are components and versions I'm using:

    Storm: 0.10.0

    Kafka_2.10: 0.9.0.1

    HDP: 2.3.4

    storm-kafka: 0.10.0

    I accomplished steps 1 and 2 using "storm.kafka.KafkaSpout" that comes with storm-kafka

    I'm trying to use "storm.kafka.KafkaBolt" to write processed data to a topic and I couldn't figure out exactly how to do it. Here is the code snippet:

      

    Properties props = new Properties();
    props.put("metadata.broker.list", "192.168.56.102:9092");
    props.put("request.required.acks", "1");
    props.put("serializer.class", "kafka.serializer.StringEncoder");
     
    Config conf = new Config();        
    conf.put(KafkaBolt.KAFKA_BROKER_PROPERTIES, props);
     
    KafkaBolt kafkaBolt = new KafkaBolt().withTopicSelector(new DefaultTopicSelector("OUTBOUND_TOPIC"))
                          .withTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper()); builder.setBolt("kafka_outbound_bolt", kafkaBolt, 3).shuffleGrouping("process_bolt");

      

    "process_bolt" sends out a tuple that is a serializable domain model object (SubModel.java). I would like to send SubModel.toString() data to the outbound topic. I'm running storm in local cluster mode connected to kafka in a local VM.

    1. Am I doing anything wrong ?
    2. How do I use "FieldNameBasedTupleToKafkaMapper"?
  • 相关阅读:
    kubeadm升级证书-集群已GG
    匿名内部类
    JAVA中Integer的==和equals注意
    编写高效优雅安全Java程序的常见原则
    图解排序算法(二)之希尔排序
    String常见问题
    ActiveMQ 2
    消息中间件概述和AaciveMQ 1
    类加载器-5
    使用MyBatis编写Dao的两种语法
  • 原文地址:https://www.cnblogs.com/twodog/p/12139578.html
Copyright © 2011-2022 走看看