コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
You need to install rabbitqm-server and
pip install librabbitmq
pip install --pre notabene
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()