0

I am trying to create a simple Python Pika SelectConnection and it seems that I am not able to open a connection using the on_open_callback and I don't get anything from te on_open_error_callback either. Can someone suggest what might be causing the problem?

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()
Tom Kregenbild
  • 1,568
  • 1
  • 10
  • 11

1 Answers1

2

Found the problem, I added the line bellow and then connection was opened and the callback worked.

self._connection.ioloop.start()
Tom Kregenbild
  • 1,568
  • 1
  • 10
  • 11