58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import json
|
|
import logging
|
|
import time
|
|
|
|
from mqtt_pub import MQTTClient
|
|
|
|
# MQTT 配置
|
|
MQTT_BROKER = "8.137.54.85"
|
|
MQTT_PORT = 1883
|
|
MQTT_PUBLISH_TOPIC = "ai/tottle/uvmodule"
|
|
# MQTT_PUBLISH_TOPIC = "ai/tottle/uvmodulecallback" # 回调topic
|
|
# MQTT_CLIENT_ID = "aitottle0123456789"
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def send_mqtt_uv_request(task_id,s3_id,s3_url,model_func_id):
|
|
mqtt_client=None
|
|
try:
|
|
mqtt_client = MQTTClient(MQTT_BROKER, MQTT_PORT, MQTT_PUBLISH_TOPIC)
|
|
except Exception as e:
|
|
logger.error(f"启动AI视频处理失败: {e}")
|
|
raise Exception(f"send_mqtt_uv_request connect to mqtt failed: {str(e)}", status_code=500)
|
|
|
|
|
|
|
|
# # 启动生产者线程
|
|
# producer = threading.Thread(target=producer_thread)
|
|
# producer.start()
|
|
|
|
# # 启动消费者线程
|
|
# consumer = threading.Thread(target=consumer_thread, args=(mqtt_client,))
|
|
# consumer.start()
|
|
|
|
# # 等待生产者线程完成
|
|
# producer.join()
|
|
if mqtt_client is not None:
|
|
request_data={
|
|
"task_id":task_id,
|
|
"s3_id":s3_id,
|
|
"list_s3_url":s3_url,
|
|
"list_func_id":model_func_id,
|
|
}
|
|
payload = json.dumps(request_data, ensure_ascii=False)
|
|
mqtt_client.publish_message(payload)
|
|
# 等待队列中的所有消息被处理
|
|
# message_queue.join()
|
|
time.sleep(0.5)
|
|
# 关闭 MQTT 客户端
|
|
# mqtt_client.close()
|
|
# time.sleep(5)
|
|
print("程序结束")
|
|
else:
|
|
print("send_mqtt_uv_request 方法执行失败") |