queue: Refactor SimpleQueueClient initialization

In anticipation of subclassing.

(imported from commit 1ebee932aed1b472bf9a8ab6d9bc30519f587c83)
This commit is contained in:
Keegan McAllister
2013-01-18 13:15:09 -05:00
parent d349de903b
commit 89c544f21f

View File

@@ -9,12 +9,17 @@ import simplejson
class SimpleQueueClient(object):
def __init__(self):
self.queues = set()
self.channel = None
self._connect()
credentials = pika.PlainCredentials('humbug', settings.RABBITMQ_PASSWORD)
parameters = pika.ConnectionParameters('localhost',
credentials=credentials)
self.connection = pika.BlockingConnection(parameters)
self.channel = self.connection.channel()
def _connect(self):
self.connection = pika.BlockingConnection(self._get_parameters())
self.channel = self.connection.channel()
def _get_parameters(self):
return pika.ConnectionParameters('localhost',
credentials = pika.PlainCredentials(
'humbug', settings.RABBITMQ_PASSWORD))
@classmethod
def get_instance(cls):
@@ -23,6 +28,9 @@ class SimpleQueueClient(object):
cls._instance = cls()
return cls._instance
def ready(self):
return self.channel is not None
def create_queue(self, queue_name):
# Initialize the queues we need
self.channel.queue_declare(queue=queue_name, durable=True)