def get_connection(self, properties, queue_name): (connection_dict, connection_tuple, exchange_dict, exchange_tuple) = self._extract_params(properties) connection_info = self.pool.get(connection_tuple) if connection_info is None: connection = driver.create_connection(connection_dict['host'], connection_dict['port'], connection_dict['user'], connection_dict['password'], connection_dict['library'], connection_dict['vhost']) connection_info = (connection, {}) self.pool[connection_tuple] = connection_info connection, exchange_pool = connection_info exchange = exchange_pool.get(exchange_tuple) if exchange is None: exchange = driver.create_exchange(exchange_dict['exchange_name'], exchange_dict['exchange_type']) exchange_pool[exchange_tuple] = exchange # Make sure the queue exists so we don't lose events. queue = driver.create_queue(queue_name, exchange, queue_name, channel=connection.channel()) queue.declare() return (connection, exchange)
pip install --pre notification_utils """ import datetime import sys from notabene import kombu_driver as driver import notification_utils import notigen connection = driver.create_connection("localhost", 5672, "guest", "guest", "librabbitmq", "/") exchange = driver.create_exchange("monitor", "topic") queue_name = "monitor.info" queue = driver.create_queue(queue_name, exchange, queue_name, channel=connection.channel()) queue.declare() print "Usage: python event_pump.py <template_dir> <operations/hour> " "<realtime? 1/0>" template_dir = sys.argv[1] rate = int(sys.argv[2]) realtime = int(sys.argv[3]) == 1 print "Using template dir:", template_dir print "Rate:", rate print "Real-time?", realtime g = notigen.EventGenerator(template_dir, rate) now = datetime.datetime.utcnow() start = now end = now + datetime.timedelta(days=1) nevents = 0
def test_create_queue(self): e = kombu_driver.create_exchange("name", "topic") kombu_driver.create_queue("name", e, "routing_key")