# import sys
# sys.path.extend(["..", "../util"])
# from util.AliyunSdk import AliyunVodSdk
# from concurrency.CommonThread import Common
from kafka import KafkaProducer
import json
import threading

# topicName = 'dsp-alg-online-tasks'
# eBody = {
#     "request_id": "d4c909912ac741ce81ccef03fd1b2ec45",
#     "models": [
#     {
#         "code": "001",
#         "categories": [{
#             "id": "0",
#             "config": {}
#         },
#         {
#             "id": "1",
#             "config": {}
#         },
#         {
#             "id": "2",
#             "config": {}
#         },
#         {
#             "id": "3",
#             "config": {}
#         }]
#     }],
#     "command": "start",
#     "pull_url": "rtmp://live.play.t-aaron.com/live/THSAj_hd",
#     "push_url": "rtmp://live.push.t-aaron.com/live/THSAk",
#     "results_base_dir": "P20220802133841159"
# }
# def on_send_success(record_metadata,aaa, ad):
#     print("kafka异步发送信息成功，topic:{}|partition:{}|offset:{}", record_metadata, aaa)
#
# def on_send_error(excp):
#     print(excp)
# producer = KafkaProducer(bootstrap_servers=['101.132.127.1:19092'],
#                          value_serializer=lambda m: json.dumps(m).encode('utf-8'))
# future = producer.send(topicName, key=b'd4c909912ac741ce81ccef03fd1b2ec45', value=eBody).add_callback(
#     on_send_success, "sdasd", "1111").add_errback(on_send_error)
# result = future.get(timeout=10)
# print(result)
aaa = {
    "erroMsg": "系统内部异常, 请联系工程师定位处理！",
    "registerRecognitionMsg": [],
    "erroCode": "SP999",
    "msgId": "ffa29db9c4c7451997b3d5038bf13381"
}
# topicName = 'fk-alg-tasks'
topicName = 'fk-alg-results'

aa = {
    "msgId": "1312313213",
    "registerMsg": [
        {
            "registerId": '12345',
            "carUrl": "https://image.t-aaron.com/imagedir/w94owdobfm_1667283710143.png",
            "flowManUrlList": [
                "https://image.t-aaron.com/imagedir/kv1mx82nje_1667373524073.png",
                # "https://image.t-aaron.com/imagedir/qbvx3c5ym2f_1667368182561.png"
            ]
        }
    ]
}
producer = KafkaProducer(bootstrap_servers=['192.168.11.13:9092'],
                         value_serializer=lambda m: json.dumps(m).encode('utf-8'))
future = producer.send(topicName, key=b'ffa29db9c4c7451997b3d5038bf13381', value=aaa)
result = future.get(timeout=10)
print(result)