""" @author: luojunhui """ import json from uuid import uuid4 from mq_http_sdk.mq_exception import MQExceptionBase from mq_http_sdk.mq_producer import TopicMessage from mq_http_sdk.mq_client import MQClient class MQ(object): """ MQ Class """ instance_id = "MQ_INST_1894469520484605_BXhXuzkZ" def __init__(self, topic_name) -> None: self.mq_client = MQClient("http://1894469520484605.mqrest.cn-qingdao-public.aliyuncs.com", "LTAI4G7puhXtLyHzHQpD6H7A", "nEbq3xWNQd1qLpdy2u71qFweHkZjSG") self.producer = self.mq_client.get_producer(self.instance_id, topic_name) def send_msg(self, params): """ send msg to mq client """ try: msg = TopicMessage(json.dumps(params)) message_key = str(uuid4()) msg.set_message_key(message_key) re_msg = self.producer.publish_message(msg) print(re_msg) except MQExceptionBase as e: print(e)