Kafka 实战
小于 1 分钟
Kafka 实战
1 maven 坐标
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
官方文档: https://spring.io/projects/spring-kafka
2 properties 配置
org.apache.kafka.clients.producer.ProducerConfig.java
spring.kafka.bootstrap-servers=localhost.ubuntu0.com:9092,localhost.ubuntu1.com:9092,localhost.ubuntu2.com:9092
3 Server 配置
主题
auto.create.topics.enable
分区
# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1
副本
############################# Internal Topic Settings #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
4 消费者配置
消费者组
spring.kafka.consumer.group-id=
自动提交 offset
spring.kafka.consumer.enable-auto-commit=false
rebalance
(全文完)