From bea38823014155115d9ad8899d8ff7c2d50ca590 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 17 Oct 2024 16:32:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A83.12=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=AD=E7=94=A8=E6=88=B7=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/settings.cpython-39.pyc | Bin 0 -> 303 bytes app.py | 20 +++++++++++++------- settings.py | 8 ++++---- 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 __pycache__/settings.cpython-39.pyc diff --git a/__pycache__/settings.cpython-39.pyc b/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e936db74611d7f97d4283fbaae30ef7a5a49c0a6 GIT binary patch literal 303 zcmYe~<>g`kg0+VP(su*t#~=r-{Q`mzUG&!Ppb5o0p6Vp@U3rkZ=Q={1PQp<}HGxMU@42_IUOwFpe3=Q=R z^bGY3O^q`(#26TEapvSFC+1}27nj^(Day|;@zdnE#pWC6mzbLx1*AiZQ;VXwd;SghFNz4FE@VPuu_i literal 0 HcmV?d00001 diff --git a/app.py b/app.py index 8bfaaf8..b3a0c08 100644 --- a/app.py +++ b/app.py @@ -13,7 +13,8 @@ def shop_random(): return shop def send_queue(data={}): - connection = pika.BlockingConnection(pika.ConnectionParameters(settings.MQHost, settings.MQPort)) + credentials = pika.PlainCredentials('newrain', '123456') + connection = pika.BlockingConnection(pika.ConnectionParameters(settings.MQHost, settings.MQPort, credentials=credentials)) channel = connection.channel() # 声明一个名为 'message_queue' 的队列 @@ -28,18 +29,21 @@ def send_queue(data={}): def read_queue(): # 建立与RabbitMQ服务器的连接 - connection = pika.BlockingConnection(pika.ConnectionParameters(settings.MQHost, settings.MQPort)) + credentials = pika.PlainCredentials('newrain', '123456') + connection = pika.BlockingConnection( + pika.ConnectionParameters(host=settings.MQHost, port=settings.MQPort, credentials=credentials) + ) channel = connection.channel() # 声明一个队列 - channel.queue_declare(queue=settings.MQName) + queue_info = channel.queue_declare(queue=settings.MQName, passive=True) # 获取队列中的消息数量 - queue_info = channel.queue_declare(queue=settings.MQName, passive=True) message_count = queue_info.method.message_count connection.close() return message_count + @app.route('/', methods=["GET", "POST"]) def index(): if request.method == 'POST': @@ -55,10 +59,12 @@ def index(): @app.route('/read', methods=["GET","POST"]) def read(): - connection = pika.BlockingConnection(pika.ConnectionParameters(settings.MQHost,settings.MQPort)) - channel = connection.channel() - + credentials = pika.PlainCredentials('newrain', '123456') + connection = pika.BlockingConnection( + pika.ConnectionParameters(host=settings.MQHost, port=settings.MQPort, credentials=credentials) + ) # 声明一个名为 'message_queue' 的队列 + channel = connection.channel() channel.queue_declare(queue=settings.MQName) data = [] diff --git a/settings.py b/settings.py index 314d93e..537b800 100644 --- a/settings.py +++ b/settings.py @@ -1,11 +1,11 @@ # rabbitmq 配置 MQName="message_queue" -MQUser="guest" -MQPassword="guest" -MQHost="localhost" +MQUser="newrain" +MQPassword="123456" +MQHost="11.0.1.153" MQPort=5672 # mysql数据库配置 DBHost="localhost" DBUser="root" -DBPassword="QianFeng@123" \ No newline at end of file +DBPassword="123456"