This commit is contained in:
2025-01-03 10:31:30 +08:00
parent e36c7f4810
commit ce9db4c25d
8 changed files with 177 additions and 66 deletions

View File

@@ -53,7 +53,7 @@ def delivery_report(err, msg):
if err is not None:
print('Message delivery failed: {}'.format(err))
else:
print('Message delivered to {} [{}]'.format(msg.topic(), msg.partition()))
# print('Message delivered to {} [{}]'.format(msg.topic(), msg.partition()))
pass
def run_kafka_producer():
@@ -61,4 +61,4 @@ def run_kafka_producer():
order_data = generate_order_data() # 生成数据
producer.produce('orders', order_data, callback=delivery_report) # 发送到 Kafka 的 orders 主题
producer.poll(0) # 处理任何待处理的事件(如回调)
time.sleep(5) # 每隔 5 秒发送一次
time.sleep(random.random()*3) # 每隔 1-5 秒发送一次