gpt4 book ai didi

Python RabbitMQ sender.py 远程队列

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:53 32 4
gpt4 key购买 nike

我正在尝试向远程计算机中的 rabbit mq 队列发送消息。我正在关注 this教程。

连接到本地主机的程序工作正常。但是连接到远程队列的程序不起作用。错误一定出在创建连接时,因为我看不到日志消息“已创建连接”。

我已经验证我可以从我的机器访问远程主机、端口并且凭据是正确的。我可以访问

http://remote-host:15672/#/queues

我是否漏掉了任何明显的东西?

本地

#!/usr/bin/env python
import pika

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

channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()

远程

#!/usr/bin/env python
import pika

# this queue is the destination queue
credentials = pika.PlainCredentials('xxxx', 'xxxx')
parameters = pika.ConnectionParameters('remote-host', 15672, '/', credentials)
connection = pika.BlockingConnection(parameters)
print " connection created"

channel = connection.channel()
channel.queue_declare(queue='hello')

channel.basic_publish(exchange='helloEx', routing_key='', body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()

更新这是我在尝试连接时遇到的错误。


ERROR:pika.adapters.base_connection:Socket Error on fd 3: 54 Traceback (most recent call last):
File "remote-sender.py", line 10, in connection = pika.BlockingConnection(parameters)
File "/Library/Python/2.7/site-packages/pika/adapters/base_connection.py", line 61, in <strong>init</strong>
super(BaseConnection, self).<strong>init</strong>(parameters, on_open_callback)
File "/Library/Python/2.7/site-packages/pika/connection.py", line 513, in <strong>init</strong> self._connect()
File "/Library/Python/2.7/site-packages/pika/connection.py", line 804, in _connect self._adapter_connect()
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 146, in _adapter_connect
self.process_data_events()
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 88, in process_data_events
if self._handle_read():
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 184, in _handle_read
super(BlockingConnection, self)._handle_read()
File "/Library/Python/2.7/site-packages/pika/adapters/base_connection.py", line 300, in _handle_read
return self._handle_error(error)
File "/Library/Python/2.7/site-packages/pika/adapters/base_connection.py", line 264, in _handle_error
self._handle_disconnect()
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 181, in _handle_disconnect
self._on_connection_closed(None, True)
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 235, in _on_connection_closed
raise exceptions.AMQPConnectionError(*self.closing)
pika.exceptions.AMQPConnectionError: (0, '')

最佳答案

使用 5672 端口而不是 15672!它应该有效!

关于Python RabbitMQ sender.py 远程队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26849117/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com