-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathProducerExample.java
More file actions
23 lines (17 loc) · 870 Bytes
/
ProducerExample.java
File metadata and controls
23 lines (17 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package org.example;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.common.serialization.StringSerializer;
public class ProducerExample {
public static void main(String[] args) {
//Creating producer properties
var properties= KafkaConfig.properties();
properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
KafkaProducer<String,String> producer= new KafkaProducer<String,String>(properties);
producer.send(new ProducerRecord<>("prices", "Test Message"));
producer.flush();
producer.close();
}
}