|
|
@ -13,7 +13,8 @@ def shop_random(): |
|
|
|
return shop |
|
|
|
return shop |
|
|
|
|
|
|
|
|
|
|
|
def send_queue(data={}): |
|
|
|
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() |
|
|
|
channel = connection.channel() |
|
|
|
|
|
|
|
|
|
|
|
# 声明一个名为 'message_queue' 的队列 |
|
|
|
# 声明一个名为 'message_queue' 的队列 |
|
|
@ -28,18 +29,21 @@ def send_queue(data={}): |
|
|
|
|
|
|
|
|
|
|
|
def read_queue(): |
|
|
|
def read_queue(): |
|
|
|
# 建立与RabbitMQ服务器的连接 |
|
|
|
# 建立与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 = 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 |
|
|
|
message_count = queue_info.method.message_count |
|
|
|
connection.close() |
|
|
|
connection.close() |
|
|
|
return message_count |
|
|
|
return message_count |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/', methods=["GET", "POST"]) |
|
|
|
@app.route('/', methods=["GET", "POST"]) |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
if request.method == 'POST': |
|
|
|
if request.method == 'POST': |
|
|
@ -55,10 +59,12 @@ def index(): |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/read', methods=["GET","POST"]) |
|
|
|
@app.route('/read', methods=["GET","POST"]) |
|
|
|
def read(): |
|
|
|
def read(): |
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(settings.MQHost,settings.MQPort)) |
|
|
|
credentials = pika.PlainCredentials('newrain', '123456') |
|
|
|
channel = connection.channel() |
|
|
|
connection = pika.BlockingConnection( |
|
|
|
|
|
|
|
pika.ConnectionParameters(host=settings.MQHost, port=settings.MQPort, credentials=credentials) |
|
|
|
|
|
|
|
) |
|
|
|
# 声明一个名为 'message_queue' 的队列 |
|
|
|
# 声明一个名为 'message_queue' 的队列 |
|
|
|
|
|
|
|
channel = connection.channel() |
|
|
|
channel.queue_declare(queue=settings.MQName) |
|
|
|
channel.queue_declare(queue=settings.MQName) |
|
|
|
data = [] |
|
|
|
data = [] |
|
|
|
|
|
|
|
|
|
|
|