Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在数据库上写入为脱离rabbitmq_Python_Pika - Fatal编程技术网

Python 在数据库上写入为脱离rabbitmq

Python 在数据库上写入为脱离rabbitmq,python,pika,Python,Pika,我是使用rabbitmq的新手。 我在做一个poc,首先我在队列rabbi_mq上写,然后我想在数据库中名为product的表上逐行写。该表包含3列(id、产品名称、价格) 请问我怎么做 我的代码下方 Sender.py connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queu

我是使用rabbitmq的新手。 我在做一个poc,首先我在队列rabbi_mq上写,然后我想在数据库中名为product的表上逐行写。该表包含3列(id、产品名称、价格)

请问我怎么做

我的代码下方

Sender.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()
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
receiver.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()
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')

你从频道上读到了什么问题?@OneCricketeer没有问题。我只是问如何在receiver.py中的表上写入数据。嗯,首先需要使用通道,然后打开数据库连接,解析数据,然后像使用任何其他变量一样写入值。这里没有任何特定于Pika库的内容会改变您实际写入数据库的方式。这是Postgres库的文档,如果您的问题仅仅是如何与数据库交互,那么您从频道读取的内容有哪些问题?@OneCricketeer没有问题。我只是问如何在receiver.py中的表上写入数据。嗯,首先需要使用通道,然后打开数据库连接,解析数据,然后像使用任何其他变量一样写入值。这里没有任何特定于Pika库的内容会改变您实际写入数据库的方式如果您的问题仅仅是如何与数据库交互,那么这里有一个Postgres库的文档