Skip to content

Commit 7151cb7

Browse files
committed
Made changes to format.
1 parent d74045f commit 7151cb7

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
<artifactId>kafka-clients</artifactId>
4545
<version>0.11.0.0</version>
4646
</dependency>
47+
4748
<dependency>
4849
<groupId>org.codehaus.jettison</groupId>
4950
<artifactId>jettison</artifactId>
5051
<version>1.2</version>
5152
</dependency>
53+
5254
</dependencies>
5355

5456
</project>

src/main/java/com/contactsunny/poc/SimpleKafkaProducer/SimpleKafkaProducerApplication.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public void run(String... args) {
4040
/*
4141
* Defining producer properties.
4242
*/
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");
5252

5353
/*
5454
Creating a Kafka Producer object with the configuration above.
5555
*/
56-
KafkaProducer<String, String> producer = new KafkaProducer<>(props);
56+
KafkaProducer<String, String> producer = new KafkaProducer<>(producerProperties);
5757

5858
/*
5959
The sendTestMessagesToKafka method will generate some random test messages
@@ -64,6 +64,7 @@ public void run(String... args) {
6464
/*
6565
Now that we've produced some test messages, let's see how to consume them using a Kafka consumer object.
6666
*/
67+
6768
/*
6869
* Defining Kafka consumer properties.
6970
*/
@@ -108,10 +109,10 @@ public void run(String... args) {
108109
* @param producer The Kafka producer we created in the run() method earlier.
109110
*/
110111
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+
*/
115116
for (int index = 0; index < 10; index++) {
116117
sendKafkaMessage("The index is now: " + index, producer, theTechCheckTopicName);
117118
}
@@ -164,9 +165,9 @@ private void sendTestMessagesToKafka(KafkaProducer<String, String> producer) {
164165

165166
/**
166167
* 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
170171
*/
171172
private static void sendKafkaMessage(String payload,
172173
KafkaProducer<String, String> producer,

0 commit comments

Comments
 (0)