<aside> 💡 - 콘솔 프로듀서로 메시지를 보내는 방법
</aside>
💻
[토픽 생성 조건]
- 토픽 명 : peter-topic
- 파티션 : 1
- 리플리케이션 팩터 : 3
💻
[java 이용한 프로듀서 예제]
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
public class KafkaBookProducer1 {
public static void main(String[] args) {
Properties props = new Properties();
//브로커 리스트
props.put("bootstrap.servers", "peter-kafka001:9092,peter-kafka002:9092,peter-kafka003:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<String, String>("peter-topic", "Apache Kafka is a distributed streaming platform"));
producer.close();
}
}