99import java .io .IOException ;
1010import java .util .Properties ;
1111
12- public class ProducerWithoutBatchingApp {
12+ /**
13+ * Creates a Producer to send messages to Kafka one by one, without Batching, or holding messages
14+ * in memory.
15+ *
16+ * This is not recommended if you are trying to achieve high throughput, as it will send each
17+ * message individually.
18+ *
19+ * It will reuse the same topic, or create it.
20+ */
21+ public class ProducerOneByOneApp {
1322
1423 private final KafkaProducer <String , String > kafkaProducer ;
1524
16- private ProducerWithoutBatchingApp () {
25+ private ProducerOneByOneApp () {
26+ // Setting Producer configs
1727 final Properties producerConfigs = new Properties ();
1828 producerConfigs .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , CommonProperties .BOOTSTRAP_SERVERS );
1929 producerConfigs .put (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG , StringSerializer .class );
@@ -30,9 +40,13 @@ private void sendRecord() {
3040 kafkaProducer .flush ();
3141 }
3242
43+ /**
44+ * Run Producer application
45+ */
3346 public static void main (String [] args ) throws IOException {
34- final ProducerWithoutBatchingApp producerWithAckApp = new ProducerWithoutBatchingApp ();
47+ final ProducerOneByOneApp producerWithAckApp = new ProducerOneByOneApp ();
3548 producerWithAckApp .sendRecord ();
49+
3650 System .out .println ("Press ENTER to exit the system" );
3751 System .in .read ();
3852 }
0 commit comments