Storm in 0.9.3 provides an abstract generic bolt kafkabolt used to implement data write Kafka, let's take a look at a concrete example and then see how it is implemented.
we use the code to annotate the way to see how the
1. Kafkabolt's predecessor component is emit (can be Spout or bolt) Spout Spout = new Spout (New fields ("Key", "message")); Builder.setspout ("spout", spout); 2. Configure the topic and predecessor tuple messages to the Kafkabolt mapping relationship kafkabolt bolt = new Kafkabolt () to the Kafka; Bolt.withtopicselector (New Defaulttopicselector ("tony-s2k")). Withtupletokafkamapper (New Fieldnamebasedtupletok Afkamapper ()); Builder.setbolt ("Forwardtokafka", Bolt, 1). shufflegrouping ("spout"); Config conf = new config (); 3. Set Kafka producer Configuration Properties props = new properties (); Props.put ("Metadata.broker.list", "10.100.90.203:9092"); Props.put ("Producer.type", "async"); Props.put ("Request.required.acks", "0"); 0, -1, 1 props.put ("Serializer.class", "Kafka.serializer.StringEncoder"); Conf.put (tridentkafkastate.kafka_broker_properties, props); Conf.put ("topic", "tony-s2k"); if (Args.length > 0) {//cluster submit. try { Stormsubmitter.submittopology ("Kafkabolttest", conf, Builder.createtopology ()); } catch (Alreadyaliveexception e) {e.printstacktrace (); } catch (Invalidtopologyexception e) {e.printstacktrace (); }}else{new Localcluster (). Submittopology ("Kafkabolttest", conf, Builder.createtopology ()); }
Complete code Reference github:https://github.com/tonylee0329/storm-example/blob/master/src/main/java/org/tony/storm_kafka/ Common/kafkabolttesttopology.java
The use and implementation of write Kafka-kafkabolt of Storm-kafka module