|
- # 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)
-
- # topicName = 'dsp-alg-offline-tasks'
- # eBody = {
- # "request_id": "d4c909912ac741ce81ccef03fd1b2ec45",
- # "models": [
- # {
- # "id": "0",
- # "config": {}
- # },
- # {
- # "id": "1",
- # "config": {}
- # },
- # {
- # "id": "2",
- # "config": {}
- # },
- # {
- # "id": "3",
- # "config": {}
- # }
- # ],
- # "command": "start",
- # "original_url": "https://vod.play.t-aaron.com/customerTrans/c49a2c620795d124f2ae4b10197b8d0e/5abebc0b-1829c2b0c66-0004-f90c-f2c-7ec68.mp4",
- # "original_type": ".mp4",
- # "results_base_dir": "P20220802133841159"
- # }
- # producer = KafkaProducer(bootstrap_servers=['192.168.10.11:9092'],
- # value_serializer=lambda m: json.dumps(m).encode('utf-8'))
- # future = producer.send(topicName, key=b'd4c909912ac741ce81ccef03fd1b2ec45', value=eBody)
- # result = future.get(timeout=10)
- # print(result)
|