Ejemplo n.º 1
0
    def run(self):
        # Open RabbitMQ connection
        connection = AsyncoreConnection(ConnectionParameters(host=self.host, credentials=self.credentials))
        channel = connection.channel()

        # Declare the queue
        channel.queue_declare(queue=self.queue, durable=True)

        # Subscribe to the queue
        channel.basic_consume(self._capture_screenshot, queue=self.queue, no_ack=True)

        # Wait for data
        asyncore_loop()
Ejemplo n.º 2
0
    def __init__(self, username=None, password=None, queue=None, host=None):
        """Sets up the connection."""
        # Save attributes
        self.username = username
        self.password = password
        self.queue = queue if queue else 'screenshots'
        self.host = host if host else 'localhost'

        # Set up credentials if applicable
        if self.username and self.password:
            self.credentials = PlainCredentials(self.username, self.password)
        else:
            self.credentials = None

        # Open RabbitMQ connection
        connection = AsyncoreConnection(ConnectionParameters(host=self.host,
                                        credentials=self.credentials))
        self.channel = connection.channel()

        # Declare the queue
        self.channel.queue_declare(queue=self.queue, durable=True)