How to parse the Kafka 1.0.0 multi-consumer example
How to analyze the Kafka 1.0.0 consumer example, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Package kafka.demo;import java.util.HashMap;import java.util.Map;import org.apache.kafka.clients.producer.KafkaProducer;import org.apache.kafka.clients.producer.ProducerRecord;/** * *
Description: kafka 1.0.0
* @ author guangshihao * @ date September 19, 2018 * * / public class KafkaProduderDemo {public static void main (String [] args) {Map props = new HashMap () / * * acks, which sets whether to send data requires feedback from the server. There are three values of 0meme 1meme 1 * 0, which means that producer will never wait for an ack from broker. This is the behavior of version 0.7. * this option provides the lowest latency, but the guarantee of persistence is the weakest, and some data will be lost when the server hangs. * 1, which means that after leader replica has received the data, producer will get an ack. * this option provides better persistence because client will not return until the server acknowledges that the request has been successfully processed. * if you just write it to leader and hang up before you can copy the leader, then the message may be lost. *-1, which means that producer does not get an ack until all ISR have received the data. * this option provides the best persistence. As long as there is one replica alive, the data will not be lost * / props.put ("acks", "1"); / / configure the default partition method props.put ("partitioner.class", "org.apache.kafka.clients.producer.internals.DefaultPartitioner") / / configure topic's serialization class props.put ("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); / / configure value's serialization class props.put ("value.serializer", "org.apache.kafka.common.serialization.StringSerializer") / * * the host corresponding to kafka broker, in the format of host1:port1,host2:port2 * / props.put ("bootstrap.servers", "bigdata01:9092,bigdata02:9092,bigdata03:9092"); / / topic String topic = "test7"; KafkaProducer
< String, String>Producer = new KafkaProducer
< String, String>(props); for (int I = 1; I