Home > other >  Kafka producers can only send part of the information, using the Java API
Kafka producers can only send part of the information, using the Java API

Time:09-28

Kafka producers can only be part of successfully sent information, there are three partitions topic
Don't know why there is only one partition producers at the time of thoroughly, can partition a much more

Java code
 import org. Apache. Kafka. Clients. Producer. *; 

Import the Java. Util. Properties;

Public class CallBackProducer {
Public static void main (String [] args) {

//create the configuration information
The Properties Properties=new Properties ();
The properties. The put (ProducerConfig BOOTSTRAP_SERVERS_CONFIG, "172.16.29.115:9092");
The properties. The put (ProducerConfig LINGER_MS_CONFIG, 50);
The properties. The put (ProducerConfig KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.com mon. Serialization. StringSerializer");
The properties. The put (ProducerConfig VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.com mon. Serialization. StringSerializer");

//create producers object
KafkaProducer Producer=new KafkaProducer<> (properties);

//send data
for(int i=0; i<20; I++) {
Producer. Send (new ProducerRecord<> (" bzzb2 ", "xuan?" + I), (the metadata, the exception) - & gt; {
If (exception==null) {
System. The out. Println (metadata) partition () + "-" + metadata. Offset ());
}
The else {
Exception. PrintStackTrace ();
}
});
}

//close resources
Producer. The close ();
}
}


The console


The partition details


Consumer spending the results

CodePudding user response:

Now appears to be the only access to a broker on the partition, temporary not clear don't have access to both sides of the other reasons
  • Related