Пример #1
0
    def test_start_worker_no_defaults(self):
        with mock.patch('kombu.connection.BrokerConnection'):
            with mock.patch('notabene.kombu_driver.Worker') as worker:
                config = {'rabbit_host': 'my host',
                          'rabbit_port': 1234,
                          'rabbit_userid': 'userid',
                          'rabbit_password': '******',
                          'rabbit_virtual_host': 'root',
                          'durable_queue': False,
                          'queue_arguments': {1:2, 3:4},
                          'topics': {'topic_1': 10, 'topic_2': 20}
                          }

                logger = mock.Mock()
                callback = mock.Mock()
                kombu_driver.start_worker(callback, "my name", 1, config, 
                                          "topic_1", logger)

                self.assertTrue(worker.run.called_once)

                # Ignore the BrokerConnection (hard to mock since it's a 
                # context handler)
                args = list(worker.call_args[0])
                del args[2]
                self.assertEqual([callback, "my name", 1, False,
                                  {1:2, 3:4}, "topic_1", 10, logger],
                                 args)
Пример #2
0
    def test_start_worker_all_defaults(self):
        with mock.patch('kombu.connection.BrokerConnection'):
            with mock.patch('notabene.kombu_driver.Worker') as worker:
                config = {'topics': {'topic_1': 10, 'topic_2': 20}}

                logger = mock.Mock()
                callback = mock.Mock()
                kombu_driver.start_worker(callback, "my name", 1, config, 
                                          "topic_1", logger)

                self.assertTrue(worker.run.called_once)

                # Ignore the BrokerConnection (hard to mock since it's a 
                # context handler)
                args = list(worker.call_args[0])
                del args[2]
                self.assertEqual([callback, "my name", 1, True,
                                  {}, "topic_1", 10, logger],
                                 args)
Пример #3
0
"""

import logging
import sys

from notabene import kombu_driver as driver


class Callback(object):
    x = 0
    def on_event(self, deployment, routing_key, body, exchange):
        print "Got:", body
        self.x += 1
        if self.x > 100000:
            sys.exit(1)

    def shutting_down(self):
        print "Shutting down"

config = {"topics":{
            "monitor":[
                {"queue":"monitor.info",
                 "routing_key":"monitor.info"},
            ]
         }}
logging.basicConfig(level=logging.DEBUG)
driver.start_worker(Callback(), "event_consumer", 1, config,
                 "monitor", logging)