개발자의 개발괴발

[kafka] Topic Message size too large 본문

개발/kafka

[kafka] Topic Message size too large

휘발성 기억력 2025. 3. 11. 21:28
반응형

1MB가 넘는 message를 produce하니 produce가 안된다.(Broker: Message size too large)

에러메세지를 확인해보니 Message size too large 라는 메세지가 나온다.

producer에서 보낼 수 있는 message.max.bytes가 기본값이 1MB이다.

보내는 메세지가 2MB라고 생각하고 넉넉히 3MB로 늘려주겠다.

produce하는 코드에서 config만 추가해주자.

	p, err := kafka.NewProducer(&kafka.ConfigMap{
		"bootstrap.servers": "127.0.0.1:9095",
		"message.max.bytes": 3 * 1024 * 1024,  // 3MB로 변경
	})
	if err != nil {
		panic(err)
	}

하지만 역시나 에러가 난다.(Delivery failed: max_message[0]@end(Broker: Message size too large))

kafka topic의 기본 max message size는 1MB이다.(max.message.bytes의 기본값이 1MB이다.)

그래서 producer에서 1MB가 넘는 값을 보내면 topic에 저장될 수 없다.

그래서 broker에서 topic의 max message size를 늘려주자.

broker에 접속해서 아래 명령어로 늘려줄 수 있다.

kafka-configs.sh --bootstrap-server localhost:9092 \
	--alter --topic $topic --add-config max.message.bytes=3145728 # 3 * 1024 * 1024

설정을 해주면 아래와 같이 나오고 설정 후에 토픽 설정을 확인해보면 2MB로 늘어난 것을 볼 수 있다.

$ kafka-configs.sh --bootstrap-server localhost:9092 \
        --alter --topic max_message --add-config max.message.bytes=3145728
Completed updating config for topic max_message.

$ kafka-topics.sh --describe --bootstrap-server localhost:9092  --topic max_message
Topic: max_message	TopicId: wwDx1x_ZSuaM4xiIwFgvpQ	PartitionCount: 1	ReplicationFactor: 1	Configs: max.message.bytes=3145728
	Topic: max_message	Partition: 0	Leader: 0	Replicas: 0	Isr: 0	Elr: 	LastKnownElr

 

다시 Produce를 해보자. 그리고 topic의 offset을 확인해보자.

아래와 같이 offset이 늘어난 것을 확인할 수 있다.

$ kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic max_message
max_message:0:10

이제 consume을 해보자.

consume을 하면 에러가 날 줄 알았는데 에러가 나지 않는다.

관련된 설정은 아래와 같다.

  • max.partition.fetch.bytes: 파티션별 반환 가능한 사이즈
  • fetch.max.bytes: fetch 요청의 최대 크기

인것 같은데 producer에서 압축하거나 아니면 fetch.max.bytes를 유연하게 사용하는것 같다.

정확한건 더 찾아봐야할 것 같다.

반응형