Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
jd_data_process
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
45aeadfb
authored
Nov 06, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add post msg
parent
378b973e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
26 deletions
push_to_mq.py
push_to_mq.py
View file @
45aeadfb
import
json
import
pika
import
pymysql
# 推送消息到 mq测试脚本
#
...
...
@@ -14,9 +15,24 @@ username = 'huntadmin'
password
=
'jy2y2900'
host
=
'172.18.137.29'
port
=
5672
queue_name
=
'liexin_
tmp_update_stock_data
'
queue_name
=
'liexin_
nplm_vc_sku_update
'
config_prod
=
{
"mysql"
:
{
"host"
:
"bigdata2.ichunt.db"
,
"port"
:
3306
,
"user"
:
"DsbuUx"
,
"password"
:
"sfj09JjsfpQx0"
,
"database"
:
"liexin_data_distribution"
},
"redis"
:
{
"host"
:
"172.18.137.38"
,
"port"
:
6379
,
"password"
:
"icDb29mLy2s"
}
}
def
push_mq
(
message
:
str
):
credentials
=
pika
.
PlainCredentials
(
username
=
username
,
password
=
password
)
conn
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
...
...
@@ -26,35 +42,33 @@ def push_mq(message: str):
))
channel
=
conn
.
channel
()
channel
.
queue_declare
(
queue
=
queue_name
,
durable
=
True
)
channel
.
basic_publish
(
exchange
=
""
,
routing_key
=
"liexin_
tmp_update_stock_data
"
,
body
=
str
.
encode
(
message
))
channel
.
basic_publish
(
exchange
=
""
,
routing_key
=
"liexin_
nplm_vc_sku_update
"
,
body
=
str
.
encode
(
message
))
channel
.
close
()
conn
.
close
()
def
post_msg
(
conf
:
dict
):
db
=
pymysql
.
connect
(
host
=
conf
[
"mysql"
][
"host"
],
port
=
3306
,
user
=
conf
[
"mysql"
][
"user"
],
password
=
conf
[
"mysql"
][
"password"
],
database
=
conf
[
"mysql"
][
"database"
])
cursor
=
db
.
cursor
()
sql
=
"SELECT spu_id, sku_id FROM lie_shop_push_sku_log WHERE platform = 1 and create_time > 1730368800 and UPDATE_time < 1730851200 and ware_id != '' ORDER BY create_time desc"
cursor
.
execute
(
query
=
sql
)
db_result
=
cursor
.
fetchall
()
for
i
in
range
(
len
(
db_result
)):
spu_id
=
db_result
[
i
][
0
]
goods_id
=
db_result
[
i
][
1
]
platform
=
1
shop_id
=
2
data
=
{
"spu_id"
:
spu_id
,
"goods_id"
:
goods_id
,
"platform"
:
platform
,
"shop_id"
:
shop_id
}
msg_str
=
json
.
dumps
(
data
,
ensure_ascii
=
False
)
push_mq
(
msg_str
)
# {"goods_id":1170115972487102103,"spu_id":2170115972437912400,"platform":1,"shop_id":1}
if
__name__
==
'__main__'
:
# data = {"goods_id": 1151525960495265804, "spu_id": 2151133166540743705, "platform": 1, "shop_id": 2}
# msg = json.dumps(data, ensure_ascii=False)
# push_mq(msg)
#
#
# data = {"goods_id": 1151033368840495919, "spu_id": 2151033368813527600, "platform": 1, "shop_id": 2}
# msg = json.dumps(data, ensure_ascii=False)
# push_mq(msg)
#
# data = {"goods_id": 1151033372498623926, "spu_id": 2151033372494531806, "platform": 1, "shop_id": 2}
# msg = json.dumps(data, ensure_ascii=False)
# push_mq(msg)
#
# data = {"goods_id": 1171169666318406723, "spu_id": 2151033370259441104, "platform": 1, "shop_id": 2}
# msg = json.dumps(data, ensure_ascii=False)
# push_mq(msg)
#
#
# data = {"goods_id": 1151033368983156030, "spu_id": 2151033369155518807, "platform": 1, "shop_id": 2}
# msg = json.dumps(data, ensure_ascii=False)
# push_mq(msg)
data
=
"1165956405456122763,1165576248018449263"
push_mq
(
data
)
\ No newline at end of file
post_msg
(
config_prod
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment