use kafka_python in sanic
1.install
pip install kafka_python
2.initialization
eg:
@app.listener('before_server_start')
async def server_init(app, loop):
kafka_host = "172.16.1.120:19092,172.16.1.121:19092,172.16.1.122:19092"
app.producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8'),
bootstrap_servers=kafka_host)
3.use
app.producer.send("topic_name", dict)
网友评论