@@ -40,20 +40,20 @@ public void run(String... args) {
40
40
/*
41
41
* Defining producer properties.
42
42
*/
43
- Properties props = new Properties ();
44
- props .put ("bootstrap.servers" , kafkaBootstrapServers );
45
- props .put ("acks" , "all" );
46
- props .put ("retries" , 0 );
47
- props .put ("batch.size" , 16384 );
48
- props .put ("linger.ms" , 1 );
49
- props .put ("buffer.memory" , 33554432 );
50
- props .put ("key.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
51
- props .put ("value.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
43
+ Properties producerProperties = new Properties ();
44
+ producerProperties .put ("bootstrap.servers" , kafkaBootstrapServers );
45
+ producerProperties .put ("acks" , "all" );
46
+ producerProperties .put ("retries" , 0 );
47
+ producerProperties .put ("batch.size" , 16384 );
48
+ producerProperties .put ("linger.ms" , 1 );
49
+ producerProperties .put ("buffer.memory" , 33554432 );
50
+ producerProperties .put ("key.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
51
+ producerProperties .put ("value.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
52
52
53
53
/*
54
54
Creating a Kafka Producer object with the configuration above.
55
55
*/
56
- KafkaProducer <String , String > producer = new KafkaProducer <>(props );
56
+ KafkaProducer <String , String > producer = new KafkaProducer <>(producerProperties );
57
57
58
58
/*
59
59
The sendTestMessagesToKafka method will generate some random test messages
@@ -64,6 +64,7 @@ public void run(String... args) {
64
64
/*
65
65
Now that we've produced some test messages, let's see how to consume them using a Kafka consumer object.
66
66
*/
67
+
67
68
/*
68
69
* Defining Kafka consumer properties.
69
70
*/
@@ -108,10 +109,10 @@ public void run(String... args) {
108
109
* @param producer The Kafka producer we created in the run() method earlier.
109
110
*/
110
111
private void sendTestMessagesToKafka (KafkaProducer <String , String > producer ) {
111
- /*
112
- Creating a loop which iterates 10 times, from 0 to 9, and sending a
113
- simple message to Kafka.
114
- */
112
+ /*
113
+ Creating a loop which iterates 10 times, from 0 to 9, and sending a
114
+ simple message to Kafka.
115
+ */
115
116
for (int index = 0 ; index < 10 ; index ++) {
116
117
sendKafkaMessage ("The index is now: " + index , producer , theTechCheckTopicName );
117
118
}
@@ -164,9 +165,9 @@ private void sendTestMessagesToKafka(KafkaProducer<String, String> producer) {
164
165
165
166
/**
166
167
* Function to send a message to Kafka
167
- * @param payload
168
- * @param producer
169
- * @param topic
168
+ * @param payload The String message that we wish to send to the Kafka topic
169
+ * @param producer The KafkaProducer object
170
+ * @param topic The topic to which we want to send the message
170
171
*/
171
172
private static void sendKafkaMessage (String payload ,
172
173
KafkaProducer <String , String > producer ,
0 commit comments