设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

从未如此简单:10分钟带你逆袭Kafka!(11)

发布时间:2020-03-23 12:31 所属栏目:119 来源:站长网
导读:kafka-topics.sh--create--bootstrap-server=192.168.51.128:9092,10.231.128.96:9093,192.168.51.128:9094--replication-factor1--partitions1--topictest1 #创建topictest2 kafka-topics.sh--create--bootstrap-s

kafka-topics.sh --create --bootstrap-server=192.168.51.128:9092,10.231.128.96:9093,192.168.51.128:9094 --replication-factor 1 --partitions 1 --topic test1 

# 创建topic test2 

kafka-topics.sh --create --bootstrap-server=192.168.51.128:9092,10.231.128.96:9093,192.168.51.128:9094 --replication-factor 1 --partitions 1 --topic test2 

# 查看topic 

kafka-topics.sh --list --bootstrap-server=192.168.51.128:9092,10.231.128.96:9093,192.168.51.128:9094  

②自动创建 Topic

我们在工作中,如果我们不想去管理 Topic,可以通过 Kafka 的配置文件来管理。

我们可以让 Kafka 自动创建 Topic,需要在我们的 Kafka 配置文件中加入如下配置文件:

auto.create.topics.enable=true 

如果删除 Topic 想达到物理删除的目的,也是需要配置的:

delete.topic.enable=true 

③发送消息

他们可以通过客户端的命令生产消息,先来看看 kafka-console-producer.sh 常用的几个参数吧:

--topic <String: topic>:指定 topic

--timeout <Integer: timeout_ms>:超时时间

--sync:异步发送消息

--broker-list <String: broker-list>:官网提示: REQUIRED: The broker list string in the form HOST1:PORT1,HOST2:PORT2.

这个参数是必须的:

kafka-console-producer.sh --broker-list 192.168.51.128:9092,192.168.51.128:9093,192.168.51.128:9094 --topic test1 

④消费消息

我们也还是先来看看 kafka-console-consumer.sh 的参数吧:

--topic <String: topic>:指定 topic

--group <String: consumer group id>:指定消费者组

--from-beginning:指定从开始进行消费, 如果不指定, 就从当前进行消费

--bootstrap-server:Kafka 的连接地址

kafka-console-consumer.sh --bootstrap-server 192.168.51.128:9092,192.168.51.128:9093,192.168.51.128:9094 --topic test1 ---beginning 

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读