12 lines
345 B
Python
12 lines
345 B
Python
from kafka import KafkaProducer
|
|
import json
|
|
|
|
producer = KafkaProducer(bootstrap_servers=['120.27.147.4:9092'],
|
|
value_serializer=lambda m: json.dumps(m).encode('ascii'))
|
|
|
|
print(producer.config)
|
|
|
|
message = {"name": "John", "age": 30}
|
|
producer.send('test-topic', message)
|
|
producer.flush() # 确保所有消息都已发送
|