리눅스/kafka

consumer에서 여러개의 topic 읽기

정지홍 2024. 10. 22. 08:17
 KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String, String>(props);
 kafkaConsumer.subscribe(List.of("topic-p3-t1", "topic-p3-t2"));

2개의 topic을 대상으로 한다.

 

 

1. consumer 코드를 실행해서 로그를 보자

위의 topic은 partition 3개로 이루어져 있으며, 총 6개의 partition들이 보인다.

 

2. 다음과 같은 producer에서 message를 보내보자.

 

 

3. 로그를 봐보자

다음과 같이 여러개의 topic에서 consumer가 읽음을 확인 할 수 있다.