将消息发送到主题的KafkaProducerException

时间:2017-07-03 10:13:55

标签: spring-boot apache-kafka kafka-producer-api spring-kafka

kafka制作人的春季启动属性:

spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.client-id=bam
#spring.kafka.producer.acks= # Number of acknowledgments the producer requires the leader to have received before considering a request complete.
spring.kafka.producer.batch-size=0
spring.kafka.producer.bootstrap-servers=localhost:9092
#spring.kafka.producer.buffer-memory= # Total bytes of memory the producer can use to buffer records waiting to be sent to the server.
spring.kafka.producer.client-id=bam-producer
spring.kafka.consumer.auto-offset-reset=earliest
#spring.kafka.producer.compression-type= # Compression type for all data generated by the producer.
spring.kafka.producer.key-serializer= org.apache.kafka.common.serialization.StringSerializer
#spring.kafka.producer.retries= # When greater than zero, enables retrying of failed sends.
spring.kafka.producer.value-serializer= org.apache.kafka.common.serialization.StringSerializer
#spring.kafka.properties.*= # Additional properties used to configure the client.

当我尝试将消息发送到kafka主题时,我正处于异常之下:

Caused by: org.springframework.kafka.core.KafkaProducerException: Failed to send; nested exception is org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for bam-0 due to 30004 ms has passed since last append
at org.springframework.kafka.core.KafkaTemplate$1.onCompletion(KafkaTemplate.java:255)
at org.apache.kafka.clients.producer.internals.RecordBatch.done(RecordBatch.java:109)
at org.apache.kafka.clients.producer.internals.RecordBatch.maybeExpire(RecordBatch.java:160)
at org.apache.kafka.clients.producer.internals.RecordAccumulator.abortExpiredBatches(RecordAccumulator.java:245)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:212)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:135)
... 1 more

引起:org.apache.kafka.common.errors.TimeoutException:由于自上次追加以来已经过了30004毫秒而导致bam-0失效1条记录

我无法弄明白为什么我会得到这个例外。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

制作人正在尝试发送消息。我注意到你在引导程序中使用localhost。确保代理在本地可用并侦听端口9092。

答案 1 :(得分:0)

通过将 server.properties 中的 advertised.listeners 设置为PLAINTEXT://< ExternalIP >:9092解决问题。

注意:Kafka部署在aws上。