kafka服务启动
1、先启动ZooKeeper服务(/usr/local/kafka):
bin/zookeeper-server-start.sh config/zookeeper.properties
2、启动kafka服务:
bin/kafka-server-start.sh config/server.properties
消息路由
上行: 中控至虚幻4 。
下行: 虚幻4至中控 。
消息主题
CC2UE: 上行消息主题 。
UE2CC: 下行消息主题 。
主题操作
1、创建主题
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic CC2UE
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic UE2CC
2、删除主题
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic CC2UE
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic UE2CC
3、列出所有主题(查看所有主题)
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
客户端测试
生产者测试
打开Producer(生产者)服务,然后键入(输入)发送信息即可。
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
ubuntu@ubuntu:/usr/local/kafka/kafka_2.12-3.0.0$
ubuntu@ubuntu:/usr/local/kafka/kafka_2.12-3.0.0$ bin/kafka-console-producer.sh --broker-list 192.168.165.242:9092 --topic test
>hello
>world
>
消费者测试
打开Customer(消费者)服务:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
ubuntu@ubuntu:/usr/local/kafka/kafka_2.12-3.0.0$
ubuntu@ubuntu:/usr/local/kafka/kafka_2.12-3.0.0$ bin/kafka-console-consumer.sh --bootstrap-server ubuntu:9092 --topic test --from-beginning
hello
world
消息生命周期设置
关于消息保留时长(消息生命周期)相关内容,请参考《kafka消息保留机制》章节。
设置消息保留时长
编辑 "/usr/local/kafka/kafka_2.12-3.0.0/config/server.properties" 配置文件的 Log Retention Policy 部分内容,修改如下两个参数:
log.retention.ms
消息保留时长,单位是:毫秒
log.retention.check.interval.ms
清理器检查日志符合被删除条件的轮询时间
单位是:毫秒
10000 (10 秒)
部分截图:
############################ Log Retention Policy #############################
# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.
# The minimum age of a log file to be eligible for deletion due to age
#log.retention.hours=168
log.retention.ms=<


4203

被折叠的 条评论
为什么被折叠?



