小编use*_*792的帖子

RabbitMQ pika.exceptions.ConnectionClosed (-1, "error(104, 'Connection reset by peer')")

我在 RabbitMQ 中有一个任务队列,其中有多个生产者 (12) 和一个消费者,用于 webapp 中的繁重任务。当我运行消费者时,它会在出现此错误之前开始将一些消息出列:

Traceback (most recent call last):
File "jobs.py", line 42, in <module> jobs[job](config)
File "/home/ec2-user/project/queue.py", line 100, in init_queue
channel.start_consuming()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1822, in start_consuming
self.connection.process_data_events(time_limit=None)
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 749, in process_data_events
self._flush_output(common_terminator)
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 477, in _flush_output
result.reason_text)
pika.exceptions.ConnectionClosed: (-1, "error(104, 'Connection reset by peer')")
Run Code Online (Sandbox Code Playgroud)

生产者代码是:

message = {'image_url': image_url, 'image_name': image_name, 'notes': notes}

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.queue_declare(queue='tasks_queue')
channel.basic_publish(exchange='', routing_key=queue_name, body=json.dumps(message))

connection.close()
Run Code Online (Sandbox Code Playgroud)

唯一的消费者代码(那个是冲突的):

def callback(self, ch, method, properties, …
Run Code Online (Sandbox Code Playgroud)

python rabbitmq python-2.7 pika python-pika

7
推荐指数
1
解决办法
7968
查看次数

标签 统计

pika ×1

python ×1

python-2.7 ×1

python-pika ×1

rabbitmq ×1