Ubuntu操作Kafka简单说明

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=<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值