您的位置:首页 > 其它

Kafka问题总结

2017-07-22 16:03 411 查看

1. 消费者无法接受消息进行消费

1、首先检查生产者是否正常发送消息

在linux启动消费者

bin/kafka-console-consumer.sh –zookeeper 192.168.6.56:2181 –topic test1 –from-beginning

如果生产者发送了消息,此时Linux开启的消费者能够消费消息,说明生产者没有问题

2、检查生产者和消费者的topic配置

生产者:

defaultTopic的配置 或 发送时指定的topic

消费者:

<!-- 消费者容器配置信息 -->
<bean id="containerProperties" class="org.springframework.kafka.listener.config.ContainerProperties">
<!-- 重要!配置topic -->
<constructor-arg value="test1"/>
<property name="messageListener" ref="messageListernerConsumerService"/>
</bean>


一般都是上面两个问题

2. Kafka启动时异常

一 、启动时内存不足

## There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# //hs_err_pid6500.logOpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000bad30000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
==========================================================


原因:kafka启动脚本kafka-server-start.sh中指定了kafka启动时需要的最小内存,默认为1G

export KAFKA_HEAP_OPTS=”-Xmx1G -Xms1G”

虚拟机分配的虚拟内存在1G以下时就会出现该错误。

解决方法:修改脚本kafka-server-start.sh中的最小启动内存,设置为较小值。

二 启动时出现oom

[ FATAL ] Fatal error during KafkaServerStable startup. Prepare to shutdown
Java.lang.OutOfMemoryError: java heap space
at java.nio.HeapByteBuffer.(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at kafka.log.SkimpyOffsetMap.(OffsetMap.Scala:42)
..........
==========================================================


原因:kafka启动时分配的内存过小导致

解决方法:同样脚本kafka-server-start.sh中的最小启动内存,设置为较大值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: