首页 > 其他分享 >Kafka学习笔记(八):Kafka CLI

Kafka学习笔记(八):Kafka CLI

时间:2023-01-08 15:01:21浏览次数:39  
标签:CLI -- topics 笔记 kafka topic sh Kafka server

Kafka CLI: kafka-topics.sh

# Replace "kafka-topics.sh" 
# by "kafka-topics" or "kafka-topics.bat" based on your system # (or bin/kafka-topics.sh or bin\windows\kafka-topics.bat if you didn't setup PATH / Environment variables)

kafka-topics.sh 

kafka-topics.sh --bootstrap-server localhost:9092 --list 

kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --create

kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --create --partitions 3

kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --create --partitions 3 --replication-factor 2

# Create a topic (working)
kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --create --partitions 3 --replication-factor 1

# List topics
kafka-topics.sh --bootstrap-server localhost:9092 --list 

# Describe a topic
kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --describe

# Delete a topic 
kafka-topics.sh --bootstrap-server localhost:9092 --topic first_topic --delete
# (only works if delete.topic.enable=true)

Kafka CLI: kafka-console-producer.sh

# Replace "kafka-console-producer.sh" 
# by "kafka-console-producer" or "kafka-console-producer.bat" based on your system # (or bin/kafka-console-producer.sh or bin\windows\kafka-console-producer.bat if you didn't setup PATH / Environment variables)

kafka-console-producer.sh 

# producing
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic 
> Hello World
>My name is Conduktor
>I love Kafka
>^C  (<- Ctrl + C is used to exit the producer)


# producing with properties
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic --producer-property acks=all
> some message that is acked
> just for fun
> fun learning!


# producing to a non existing topic
# 会自动帮你创建一个新的主题,默认partition=1 
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic new_topic
> hello world!

# our new topic only has 1 partition
kafka-topics.sh --bootstrap-server localhost:9092 --list
kafka-topics.sh --bootstrap-server localhost:9092 --topic new_topic --describe


# edit config/server.properties or config/kraft/server.properties
# num.partitions=3

# produce against a non existing topic again
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic new_topic_2
hello again!

# this time our topic has 3 partitions
kafka-topics.sh --bootstrap-server localhost:9092 --list
kafka-topics.sh --bootstrap-server localhost:9092 --topic new_topic_2 --describe

# overall, please create topics before producing to them!


# produce with keys
kafka-console-producer --bootstrap-server localhost:9092 --topic first_topic --property parse.key=true --property key.separator=:
>example key:example value
>name:Stephane

标签:CLI,--,topics,笔记,kafka,topic,sh,Kafka,server
From: https://www.cnblogs.com/Bota5ky/p/17034675.html

相关文章

  • JavaScript笔记
    变量作用域:1、全局变量:在全局作用域下声明的变量​ 在函数内部没有声明直接赋值的变量也是属于全局变量全局变量:只有浏览器关闭的时候才会销毁,比较占内存资源局部......
  • 学习笔记——Maven的基本配置、Maven基本使用、将Maven整合到IDEA中
    2023-01-08一、Maven的基本配置(1)maven配置文件位置maven根目录/conf/settings.xml①设置本地仓库默认的本地仓库是在“C:\Users\Lenovo\.m2\repository”中,第一次安装......
  • vue-cli更改包管理器yarn为npm
    找到路径C:\Users{当前登录的用户名}\下的.vuerc文件打开此文件,修改packageManager的值就可以了如果你想在项目中使用npm包管理工具,就将其值改为"npm"如果你想在项目中......
  • 【学习笔记 / 数据结构】线段树进阶
    扫描线【洛谷模板题传送门】思想以一条法线从下往上扫描整个图形,图形面积并即为\(\sum\limits_{i=1}^{n-1}len_i\times\left(h_{i+1}-h_i\right)\),其中\(len_i\)......
  • 【学习笔记】Splay
    \(\texttt{0x01}\)前言Splay树(伸展树)由DanielSleator和RobertTarjan于1985年发明。它凭借旋转可以有$O(\logn)$插入,删除等的较优秀的时间复杂度。前置芝士......
  • 【学习笔记 / 长期更新】OI 中的数论
    -Preface0.1前言本文意为作者从\(0\)开始学习数论,同时也对OIWiki的某些内容做补充说明。如果你看到有一些小标题没有内容,很正常,作者\(\color{white}\small\textb......
  • 【学习笔记】动态树 Link-Cut Tree
    -闲话LCT优秀博客:FlashHu大佬的cnblogs:https://www.cnblogs.com/flashhu/p/8324551.html-动态树Link-CutTree-前置知识「必学」Splay。「重要」树链剖分......
  • 新概念第一册111~120单元学习笔记
    Chapterhundredandeleven:ThemostexpensivemodelDialogue标题用到more的用法more/themost+adj.#多音节(>=2)形容词,前加more,most表更多less/theleast+adj.#少......
  • Airtest学习笔记之自定义启动器
    小站注:之前在《Airtest命令行运行airtestrun详解》中讲解到runner.py就没讲了,这篇里详细讲了runner.py的代码通过本篇,你将了解到Airtest的自定义启动器的运用,以及air......
  • 学习笔记——Maven
    2023-01-08一、Maven1.使用“Maven”的原因①获取第三方jar包可以统一在一个地方下载资源jar包(位置在“阿里云的镜像服务器”)②添加第三方jar包jar包统一存储Maven本......