ฉันกำลังพยายามส่งข้อความไปยังคิว rabbit mq ในเครื่องระยะไกล ฉันกำลังติดตามบทแนะนำนี้
โปรแกรมเชื่อมต่อกับ localhost ทำงานได้ดี แต่โปรแกรมเชื่อมต่อกับคิวระยะไกลไม่ทำงาน ข้อผิดพลาดจะต้องอยู่เมื่อสร้างการเชื่อมต่อ เพราะฉันไม่เห็นข้อความบันทึก 'สร้างการเชื่อมต่อแล้ว'
ฉันได้ตรวจสอบแล้วว่าฉันสามารถเข้าถึงโฮสต์ระยะไกล พอร์ตจากเครื่องของฉัน และข้อมูลประจำตัวนั้นถูกต้อง ฉันสามารถเข้าถึงได้
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 init
super(BaseConnection, self).init(parameters, on_open_callback)
File "/Library/Python/2.7/site-packages/pika/connection.py", line 513, in init 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, '')