Commit 6338a78e by larosa

add push mq

parent a5027a7f
Showing with 4 additions and 5 deletions
...@@ -15,7 +15,7 @@ username = 'huntadmin' ...@@ -15,7 +15,7 @@ username = 'huntadmin'
password = 'jy2y2900' password = 'jy2y2900'
host = '172.18.137.29' host = '172.18.137.29'
port = 5672 port = 5672
queue_name = 'liexin_nplm_vc_sku_update' # queue_name = 'liexin_nplm_vc_sku_update'
config_prod = { config_prod = {
...@@ -33,7 +33,7 @@ config_prod = { ...@@ -33,7 +33,7 @@ config_prod = {
} }
} }
def push_mq(message: str): def push_mq(message: str, queue_name: str, routing_key: str):
credentials = pika.PlainCredentials(username=username, password=password) credentials = pika.PlainCredentials(username=username, password=password)
conn = pika.BlockingConnection(pika.ConnectionParameters( conn = pika.BlockingConnection(pika.ConnectionParameters(
host=host, host=host,
...@@ -42,7 +42,7 @@ def push_mq(message: str): ...@@ -42,7 +42,7 @@ def push_mq(message: str):
)) ))
channel = conn.channel() channel = conn.channel()
channel.queue_declare(queue=queue_name, durable=True) channel.queue_declare(queue=queue_name, durable=True)
channel.basic_publish(exchange="", routing_key="liexin_nplm_vc_sku_update", body=str.encode(message)) channel.basic_publish(exchange="", routing_key=routing_key, body=str.encode(message))
channel.close() channel.close()
conn.close() conn.close()
...@@ -66,7 +66,6 @@ def post_msg(conf: dict): ...@@ -66,7 +66,6 @@ def post_msg(conf: dict):
"shop_id": shop_id "shop_id": shop_id
} }
msg_str = json.dumps(data, ensure_ascii=False) msg_str = json.dumps(data, ensure_ascii=False)
push_mq(msg_str)
# {"goods_id":1170115972487102103,"spu_id":2170115972437912400,"platform":1,"shop_id":1} # {"goods_id":1170115972487102103,"spu_id":2170115972437912400,"platform":1,"shop_id":1}
...@@ -91,7 +90,7 @@ def post_jd_is_null(conf: dict): ...@@ -91,7 +90,7 @@ def post_jd_is_null(conf: dict):
"shop_id": shop_id "shop_id": shop_id
} }
msg_str = json.dumps(data, ensure_ascii=False) msg_str = json.dumps(data, ensure_ascii=False)
push_mq(msg_str) push_mq(msg_str, "liexin_nplm_filter_sku_data", "liexin_nplm_filter_sku_data")
print("push msg : %s" % msg_str) print("push msg : %s" % msg_str)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment