当前位置: 首页>>代码示例>>Python>>正文


Python connection.BrokerConnection类代码示例

本文整理汇总了Python中kombu.connection.BrokerConnection的典型用法代码示例。如果您正苦于以下问题:Python BrokerConnection类的具体用法?Python BrokerConnection怎么用?Python BrokerConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BrokerConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_publish__consume

    def test_publish__consume(self):
        connection = BrokerConnection(transport=Transport)
        channel = connection.channel()
        producer = Producer(channel, self.exchange, routing_key="test_Redis")
        consumer = Consumer(channel, self.queue)

        producer.publish({"hello2": "world2"})
        _received = []

        def callback(message_data, message):
            _received.append(message_data)
            message.ack()

        consumer.register_callback(callback)
        consumer.consume()

        self.assertTrue(channel._poller._can_start())
        try:
            connection.drain_events(timeout=1)
            self.assertTrue(_received)
            self.assertFalse(channel._poller._can_start())
            self.assertRaises(socket.timeout,
                              connection.drain_events, timeout=0.01)
        finally:
            channel.close()
开发者ID:abourget,项目名称:kombu,代码行数:25,代码来源:test_transport_pyredis.py

示例2: create_connection

def create_connection():
    conn = BrokerConnection("localhost",
                            "fred",
                            "fred123",
                            "home")
    channel = conn.channel()
    return channel
开发者ID:lefred,项目名称:centipede,代码行数:7,代码来源:views.py

示例3: _do_test

 def _do_test():
     conn = BrokerConnection(transport=Transport)
     chan = conn.channel()
     self.assertTrue(chan.Client)
     self.assertTrue(chan.ResponseError)
     self.assertTrue(conn.transport.connection_errors)
     self.assertTrue(conn.transport.channel_errors)
开发者ID:crankycoder,项目名称:zamboni-lib,代码行数:7,代码来源:test_transport_redis.py

示例4: test_close_disconnects

 def test_close_disconnects(self):
     c = BrokerConnection(transport=Transport).channel()
     conn1 = c.client.connection
     conn2 = c.subclient.connection
     c.close()
     self.assertTrue(conn1.disconnected)
     self.assertTrue(conn2.disconnected)
开发者ID:crankycoder,项目名称:zamboni-lib,代码行数:7,代码来源:test_transport_redis.py

示例5: test_parse_generated_as_uri

 def test_parse_generated_as_uri(self):
     conn = BrokerConnection(self.url)
     info = conn.info()
     for k, v in self.expected.items():
         self.assertEqual(info[k], v)
     # by default almost the same- no password
     self.assertEqual(conn.as_uri(), self.nopass)
     self.assertEqual(conn.as_uri(include_password=True), self.url)
开发者ID:AshishNamdev,项目名称:mozillians,代码行数:8,代码来源:test_connection.py

示例6: create_connection

def create_connection(config):
    conn = BrokerConnection(config.get("connection", "hostname"),
                                  config.get("connection", "userid"),
                                  config.get("connection", "password"),
                                  config.get("connection", "virtual_host"))
    channel = conn.channel()

    return channel
开发者ID:lefred,项目名称:centipede,代码行数:8,代码来源:connection.py

示例7: get_connection

 def get_connection(self, vhost):
     if vhost in self.connections:
         connection = self.connections[vhost]
     else:
         connection = BrokerConnection(settings.AMQP_URL + vhost)
     if not connection.connected:
         connection.connect()
     return connection
开发者ID:PyKaB,项目名称:httpQ,代码行数:8,代码来源:server.py

示例8: setup_rabbit_mq_channel

 def setup_rabbit_mq_channel(self):
     service_exchange = Exchange(self.acord_control_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(self.rabbit_host, self.rabbit_user, self.rabbit_password)
     logging.info("Connection to RabbitMQ server successful")
     channel = connection.channel()
     # produce
     self.producer = Producer(channel, exchange=service_exchange, routing_key='notifications.info')
开发者ID:rdudyala,项目名称:udpagent,代码行数:8,代码来源:udpagent.py

示例9: setup_rabbit_mq_channel

def setup_rabbit_mq_channel():
     global producer
     global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id
     vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     print 'Connection to RabbitMQ server successful'
     channel = connection.channel()
     # produce
     producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info')
开发者ID:srikanthvavila,项目名称:ceilometer-plugins,代码行数:10,代码来源:sample_event_publisher.py

示例10: setup_rabbit_mq_channel

 def setup_rabbit_mq_channel(self):
     service_exchange = Exchange(cfg.CONF.udpservice.acord_control_exchange, "topic", durable=False)
     rabbit_host = cfg.CONF.udpservice.rabbit_hosts
     rabbit_user = cfg.CONF.udpservice.rabbit_userid 
     rabbit_password = cfg.CONF.udpservice.rabbit_password
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     print 'Connection to RabbitMQ server successful'
     channel = connection.channel()
     # produce
     self.producer = Producer(channel, exchange=service_exchange, routing_key='notifications.info')
开发者ID:rdudyala,项目名称:ceilometer_custom_plugin,代码行数:11,代码来源:udpservice.py

示例11: init_rabbit_mq

 def init_rabbit_mq(self):
     self.logger.info("Initializing RabbitMQ stuff")
     try:
         schedule_exchange = Exchange("airtime-pypo", "direct", durable=True, auto_delete=True)
         schedule_queue = Queue("pypo-fetch", exchange=schedule_exchange, key="foo")
         connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], config["rabbitmq_vhost"])
         channel = connection.channel()
         self.simple_queue = SimpleQueue(channel, schedule_queue)
     except Exception, e:
         self.logger.error(e)
         return False
开发者ID:vonloxx,项目名称:Airtime,代码行数:11,代码来源:pypomessagehandler.py

示例12: AMQPWorker

class AMQPWorker(Worker):

    queues = [
        {'routing_key': 'test',
         'name': 'test',
         'handler': 'handle_test'
        }
    ]

    _connection = None

    def handle_test(self, body, message):
        log.debug("Handle message: %s" % body)
        message.ack()

    def handle(self):
        log.debug("Start consuming")
        exchange = Exchange('amqp.topic', type='direct', durable=True)
        self._connection = BrokerConnection(*CONNECTION)
        channel = self._connection.channel()

        for entry in self.queues:
            log.debug("prepare to consume %s" % entry['routing_key'])
            queue = Queue(entry['name'], exchange=exchange,
                          routing_key=entry['routing_key'])
            consumer = Consumer(channel, queue)
            consumer.register_callback(getattr(self, entry['handler']))
            consumer.consume()

        log.debug("start consuming...")
        while True:
            try:
                self._connection.drain_events()
            except socket.timeout:
                log.debug("nothing to consume...")
                break
        self._connection.close()

    def run(self):
        while self.alive:
            try:
                self.handle()
            except Exception:
                self.alive = False
                raise

    def handle_quit(self, sig, frame):
        if self._connection is not None:
            self._connection.close()
        self.alive = False

    def handle_exit(self, sig, frame):
        if self._connection is not None:
            self._connection.close()
        self.alive = False
        sys.exit(0)
开发者ID:alepharchives,项目名称:pistil,代码行数:56,代码来源:amqp.py

示例13: send_end

def send_end(num):
    connection = BrokerConnection(hostname = 'myhost',
                                  userid = 'webfis',
                                  password = 'password',
                                  virtual_host = 'webfishost',
                                  port = 5672)
    publisher = Publisher(connection=connection,
                          exchange="end",
                          routing_key="end"+str(num),
                          exchange_type="direct")

    publisher.send("end")
    publisher.close()
    connection.release()
开发者ID:youcefhd,项目名称:magisterka,代码行数:14,代码来源:utils.py

示例14: setup_rabbit_mq_channel

def setup_rabbit_mq_channel():
     global producer
     global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id
     vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     logger.info('Connection to RabbitMQ server successful')
     channel = connection.channel()
     # produce
     producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info')
     p = subprocess.Popen('hostname', shell=True, stdout=subprocess.PIPE)
     (hostname, error) = p.communicate()
     cpe_publisher_id = cpe_publisher_id + '_on_' + hostname
     logger.info('cpe_publisher_id=%s',cpe_publisher_id)
开发者ID:albertoflorez,项目名称:xos,代码行数:14,代码来源:vcpe_stats_notifier.py

示例15: test_close_survives_connerror

    def test_close_survives_connerror(self):

        class _CustomError(Exception):
            pass

        class MyTransport(Transport):
            connection_errors = (_CustomError, )

            def close_connection(self, connection):
                raise _CustomError("foo")

        conn = BrokerConnection(transport=MyTransport)
        conn.connect()
        conn.close()
        self.assertTrue(conn._closed)
开发者ID:flaper87,项目名称:kombu,代码行数:15,代码来源:test_connection.py


注:本文中的kombu.connection.BrokerConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。