The use and implementation of write Kafka-kafkabolt of Storm-kafka module

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.