1

I have implemented a Logger Bolt in storm, the input of the tuple is coming from Kafka Topic. I am using Kafka Connect to listen to changes to mySQL database.

public class LoggerBolt extends BaseBasicBolt {

  private static final long serialVersionUID = 1L;
  private static final Logger LOG = Logger.getLogger(LoggerBolt.class);


  public void execute(Tuple input, BasicOutputCollector collector) {
     System.out.println(input.getValue(0));
  }

  public void declareOutputFields(OutputFieldsDeclarer declarer) {
  }
}

When run on local cluster below gets printed.

Q�%Buckley, Rose RoseBuckley"BuckleyR@univ.edu"963.555.6855x5018963.777.5233Curator Q� Stanton, Kathie KathieStanton"StantonK@univ.edu963.555.7095963.777.1015Professor Q�Banks, Shannon Shannon BanksBanksS@univ.edu963.555.7198963.777.6979Professor Q�/Barnes, Cleo CleoBarnes BarnesC@univ.edu"963.555.7463x7335963.777.1583$Research Professor

I want to cast these details to Person Object, which is a model class? How do we parse the Tuple input into an object?

I tried input.getValues(0) , input.getFields(0) and other method, none seems to work.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Amar Kumar
  • 57
  • 8
  • What is the type of input.getValue(0)? (try printing input.getValue(0).getClass()) Is it already a Person or a String or something else? – Stig Rohde Døssing May 03 '19 at 12:00
  • input is TupleImpl input.getValue is Avro – Amar Kumar May 03 '19 at 13:16
  • Ok. I think you need to go look at how you're serializing the data before writing to Kafka. Once you know how the data is serialized, we will have an easier time telling how you should deserialize it. Also please note whether you're using the storm-kafka or storm-kafka-client spout. – Stig Rohde Døssing May 03 '19 at 14:53
  • How do you configure Kafka deserializers in Storm? Or does it always assume Strings? – OneCricketeer May 03 '19 at 18:40

1 Answers1

0

If you're using storm-kafka-client, it assumes Strings by default. You can choose something else by doing e.g. kafkaSpoutConfig.setProp(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);. The class you set just has to implement the Kafka Deserializer interface https://kafka.apache.org/11/javadoc/org/apache/kafka/common/serialization/Deserializer.html.

There's an equivalent setting for setting the key deserializer.

Stig Rohde Døssing
  • 3,621
  • 2
  • 7
  • 7