首页 > 解决方案 > 用rabbitmq在数据库上写

问题描述

我是新来使用rabbitmq的。我正在做一个 poc,首先我在队列 rabbi_mq 上写入,然后我想在我的数据库中名为 product 的表上逐行写入。该表包含 3 列(id、product_name、price)

请问我该怎么做?

在我的代码下面

发件人.py

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body= 'x12, table, 30$')
channel.basic_publish(exchange='', routing_key='hello', body= 'x13, tv, 200$')
channel.basic_publish(exchange='', routing_key='hello', body= 'x14, desk, 100$')
print('published message')
connection.close()

接收者.py

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')

标签: pythonpika

解决方案


推荐阅读