Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
my_flask_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 478e563b
authored
Jan 30, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加kafka消费
1 parent
fe0b2490
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletions
kafka_consumer/test01.py
kafka_consumer/test02.py
kafka_consumer/test01.py
View file @
478e563
...
@@ -2,7 +2,7 @@ from kafka import KafkaConsumer
...
@@ -2,7 +2,7 @@ from kafka import KafkaConsumer
# 创建Kafka消费者
# 创建Kafka消费者
consumer
=
KafkaConsumer
(
consumer
=
KafkaConsumer
(
"
gps_gpsandbs_pingan2
"
,
# Kafka主题名称
"
my-yang-topic
"
,
# Kafka主题名称
bootstrap_servers
=
"192.168.3.131:9092"
,
# Kafka集群的地址
bootstrap_servers
=
"192.168.3.131:9092"
,
# Kafka集群的地址
group_id
=
"my-yang-group"
,
# 消费者组ID
group_id
=
"my-yang-group"
,
# 消费者组ID
)
)
...
...
kafka_consumer/test02.py
0 → 100644
View file @
478e563
from
kafka
import
KafkaProducer
# 创建Kafka生产者
producer
=
KafkaProducer
(
bootstrap_servers
=
"192.168.3.131:9092"
)
# Kafka集群的地址
# 发送消息
topic
=
"my-yang-topic"
# Kafka主题名称
key
=
b
"my-key"
# 消息的键(可选)
value
=
b
"my-value"
# 消息的值
producer
.
send
(
topic
,
key
=
key
,
value
=
value
)
# 等待所有消息发送完成
producer
.
flush
()
# 关闭生产者
producer
.
close
()
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment