我正在尝试创建一个简单的 Python Pika SelectConnection,但似乎我无法使用 on_open_callback 打开连接,而且我也没有从 te on_open_error_callback 获得任何信息。有人可以建议可能导致问题的原因吗?
import pika
class RabbitmqTransport(object):
def __init__(self):
self._connection = None
self._channel = None
self._connect()
def on_connection_open(self):
print "connection created"
def on_connection_open_error(self):
print "connection open error"
def _connect(self):
# Setup RabbitMQ connection
credentials = pika.PlainCredentials('guest','guest')
parameters = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')
print "Creating Connection"
self._connection = pika.SelectConnection(parameters=parameters,on_open_callback=self.on_connection_open,on_open_error_callback=self.on_connection_open_error)
print self._connection.connection_state
print dir(self._connection)
print self._connection.is_open
r = RabbitmqTransport()