You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

producer_start.py 2.3KB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # import sys
  2. # sys.path.extend(["..", "../util"])
  3. # from util.AliyunSdk import AliyunVodSdk
  4. # from concurrency.CommonThread import Common
  5. from kafka import KafkaProducer
  6. import json
  7. import threading
  8. topicName = 'dsp-alg-online-tasks'
  9. eBody = {
  10. "request_id": "d4c909912ac741ce81ccef03fd1b2ec45",
  11. "models": [
  12. {
  13. "code": "001",
  14. "categories": [{
  15. "id": "0",
  16. "config": {}
  17. },
  18. {
  19. "id": "1",
  20. "config": {}
  21. },
  22. {
  23. "id": "2",
  24. "config": {}
  25. },
  26. {
  27. "id": "3",
  28. "config": {}
  29. }]
  30. }],
  31. "command": "start",
  32. "pull_url": "rtmp://live.play.t-aaron.com/live/THSAj_hd",
  33. "push_url": "rtmp://live.push.t-aaron.com/live/THSAk",
  34. "results_base_dir": "P20220802133841159"
  35. }
  36. def on_send_success(record_metadata,aaa, ad):
  37. print("kafka异步发送信息成功,topic:{}|partition:{}|offset:{}", record_metadata, aaa)
  38. def on_send_error(excp):
  39. print(excp)
  40. producer = KafkaProducer(bootstrap_servers=['101.132.127.1:19092'],
  41. value_serializer=lambda m: json.dumps(m).encode('utf-8'))
  42. future = producer.send(topicName, key=b'd4c909912ac741ce81ccef03fd1b2ec45', value=eBody).add_callback(
  43. on_send_success, "sdasd", "1111").add_errback(on_send_error)
  44. result = future.get(timeout=10)
  45. print(result)
  46. # topicName = 'dsp-alg-offline-tasks'
  47. # eBody = {
  48. # "request_id": "d4c909912ac741ce81ccef03fd1b2ec45",
  49. # "models": [
  50. # {
  51. # "id": "0",
  52. # "config": {}
  53. # },
  54. # {
  55. # "id": "1",
  56. # "config": {}
  57. # },
  58. # {
  59. # "id": "2",
  60. # "config": {}
  61. # },
  62. # {
  63. # "id": "3",
  64. # "config": {}
  65. # }
  66. # ],
  67. # "command": "start",
  68. # "original_url": "https://vod.play.t-aaron.com/customerTrans/c49a2c620795d124f2ae4b10197b8d0e/5abebc0b-1829c2b0c66-0004-f90c-f2c-7ec68.mp4",
  69. # "original_type": ".mp4",
  70. # "results_base_dir": "P20220802133841159"
  71. # }
  72. # producer = KafkaProducer(bootstrap_servers=['192.168.10.11:9092'],
  73. # value_serializer=lambda m: json.dumps(m).encode('utf-8'))
  74. # future = producer.send(topicName, key=b'd4c909912ac741ce81ccef03fd1b2ec45', value=eBody)
  75. # result = future.get(timeout=10)
  76. # print(result)