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


Python AMQPTransport.qos_impl方法代码示例

本文整理汇总了Python中pyon.net.transport.AMQPTransport.qos_impl方法的典型用法代码示例。如果您正苦于以下问题:Python AMQPTransport.qos_impl方法的具体用法?Python AMQPTransport.qos_impl怎么用?Python AMQPTransport.qos_impl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.net.transport.AMQPTransport的用法示例。


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

示例1: _new_transport

# 需要导入模块: from pyon.net.transport import AMQPTransport [as 别名]
# 或者: from pyon.net.transport.AMQPTransport import qos_impl [as 别名]
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast("AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        transport = AMQPTransport(amq_chan)

        # by default, everything should have a prefetch count of 1 (configurable)
        # this can be overridden by the channel get_n related methods
        transport.qos_impl(prefetch_count=CFG.get_safe('container.messaging.endpoint.prefetch_count', 1))

        return transport
开发者ID:ateranishi,项目名称:pyon,代码行数:21,代码来源:messaging.py

示例2: TestAMQPTransportCommonMethods

# 需要导入模块: from pyon.net.transport import AMQPTransport [as 别名]
# 或者: from pyon.net.transport.AMQPTransport import qos_impl [as 别名]

#.........这里部分代码省略.........
                                                   queue=sentinel.queue,
                                                   exchange=sentinel.exchange,
                                                   routing_key=sentinel.binding)

    def test_ack_impl(self):
        self.tp.ack_impl(sentinel.dtag)

        self.tp._client.basic_ack.assert_called_once_with(sentinel.dtag)

    def test_reject_impl(self):
        self.tp.reject_impl(sentinel.dtag)

        self.tp._client.basic_reject.assert_called_once_with(sentinel.dtag, requeue=False)

    def test_start_consume_impl(self):
        rettag = self.tp.start_consume_impl(sentinel.callback, sentinel.queue)

        self.tp._client.basic_consume.assert_called_once_with(sentinel.callback,
                                                              queue=sentinel.queue,
                                                              no_ack=False,
                                                              exclusive=False)

        self.assertEquals(rettag, self.tp._client.basic_consume.return_value)

    def test_stop_consume_impl(self):
        self.tp.stop_consume_impl(sentinel.ctag)

        self.tp._sync_call.assert_called_once_with(self.tp._client.basic_cancel,
                                                   'callback',
                                                   sentinel.ctag)

    @patch('pyon.net.transport.sleep', Mock())      # patch to make sleep() be a mock call and therefore superfast
    def test_stop_consume_remains_in_consumers(self):
        self.tp._client._consumers = [sentinel.ctag]
        self.assertRaises(TransportError, self.tp.stop_consume_impl, sentinel.ctag)

    @patch('pyon.net.transport.sleep')
    def test_stop_consume_eventually_removed(self, sleepmock):
        self.tp._client._consumers.__contains__.side_effect = [True, False, False] # is checked once more at exit of method

        self.tp.stop_consume_impl(sentinel.ctag)
        sleepmock.assert_called_once_with(1)

    def test_setup_listener(self):
        cb = Mock()
        self.tp.setup_listener(sentinel.binding, cb)

        cb.assert_called_once_with(self.tp, sentinel.binding)

    def test_get_stats_impl(self):
        mo = Mock()
        self.tp._sync_call.return_value = mo
        ret = self.tp.get_stats_impl(sentinel.queue)

        self.tp._sync_call.assert_called_once_with(self.tp._client.queue_declare,
                                                   'callback',
                                                   queue=sentinel.queue,
                                                   passive=True)

        self.assertEquals(ret, (mo.method.message_count, mo.method.consumer_count))

    def test_purge_impl(self):
        self.tp.purge_impl(sentinel.queue)

        self.tp._sync_call.assert_called_once_with(self.tp._client.queue_purge,
                                                   'callback',
                                                   queue=sentinel.queue)

    def test_qos_impl(self):
        self.tp.qos_impl()

        self.tp._sync_call.assert_called_once_with(self.tp._client.basic_qos,
                                                   'callback',
                                                   prefetch_size=0,
                                                   prefetch_count=0,
                                                   global_=False)

    @patch('pyon.net.transport.BasicProperties')
    def test_publish_impl(self, bpmock):
        self.tp.publish_impl(sentinel.exchange, sentinel.routing_key, sentinel.body, sentinel.properties)

        self.tp._client.basic_publish.assert_called_once_with(exchange=sentinel.exchange,
                                                              routing_key=sentinel.routing_key,
                                                              body=sentinel.body,
                                                              properties=bpmock(headers=sentinel.properties,
                                                                                delivery_mode=None),
                                                              immediate=False,
                                                              mandatory=False)

    @patch('pyon.net.transport.BasicProperties')
    def test_publish_impl_durable(self, bpmock):
        self.tp.publish_impl(sentinel.exchange, sentinel.routing_key, sentinel.body, sentinel.properties, durable_msg=True)

        self.tp._client.basic_publish.assert_called_once_with(exchange=sentinel.exchange,
                                                              routing_key=sentinel.routing_key,
                                                              body=sentinel.body,
                                                              properties=bpmock(headers=sentinel.properties,
                                                                                delivery_mode=2),
                                                              immediate=False,
                                                              mandatory=False)
开发者ID:caseybryant,项目名称:pyon,代码行数:104,代码来源:test_transport.py


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