import asyncio loop = asyncio.get_event_loop() import json from aiokafka import AIOKafkaProducer import time localtime = int(time.time()) async def send_one(): producer = AIOKafkaProducer( # kafka集群地址 loop=loop, bootstrap_servers='?:::9092') # Get cluster layout and initial topic/partition leadership information await producer.start() try: for i in range(10): data = { "to_address":"@", # 消息类型(1 数据,2 end) "template_id": "", "more_info": { "username": "test_user" }, "personal_task_snap_shot": { "msg_type": 1, "extra_info": "", "user_id":, "version_id": 180, "task_id": 312, "userlist_id": 500, "record_id": 500, "cur_element_id": 430, "label_groups": [ { "label_id": 1, "label_name": "", "label_type": 1, "label_value": "" } ], "next_exec_time": localtime, "enqueue_time": localtime, "first_comms_time": localtime, "last_comms_time": localtime } } await producer.send_and_wait("?", json.dumps(data).encode()) #await producer.send_and_wait("?", json.dumps(data).encode()) print("i=",i) except Exception as e: print(e) finally: await producer.stop() # print(json.dumps(data)) loop.run_until_complete(send_one())
kafka幂等
最新推荐文章于 2024-08-18 21:26:41 发布