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


Python Queue.bind方法代码示例

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


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

示例1: test_also_binds_exchange

# 需要导入模块: from kombu.entity import Queue [as 别名]
# 或者: from kombu.entity.Queue import bind [as 别名]
 def test_also_binds_exchange(self):
     chan = Channel()
     b = Queue("foo", self.exchange)
     self.assertFalse(b.is_bound)
     self.assertFalse(b.exchange.is_bound)
     b = b.bind(chan)
     self.assertTrue(b.is_bound)
     self.assertTrue(b.exchange.is_bound)
     self.assertIs(b.channel, b.exchange.channel)
     self.assertIsNot(b.exchange, self.exchange)
开发者ID:EnTeQuAk,项目名称:kombu,代码行数:12,代码来源:test_entities.py

示例2: call

# 需要导入模块: from kombu.entity import Queue [as 别名]
# 或者: from kombu.entity.Queue import bind [as 别名]
    def call(self, name, operation, timeout=10, args=None, **kwargs):
        """Send a message and wait for reply

        @param name: name of destination service queue
        @param operation: name of service operation to invoke
        @param timeout: RPC timeout to await a reply
        @param args: dictionary of keyword args to pass to operation.
                     Use this OR kwargs.
        @param kwargs: additional args to pass to operation
        """

        if args:
            if kwargs:
                raise TypeError("specify args dict or keyword arguments, not both")
        else:
            args = kwargs

        # create a direct queue for the reply. This may end up being a
        # bottleneck for performance: each rpc call gets a brand new
        # exclusive queue. However this approach is used nova.rpc and
        # seems to have carried them pretty far. If/when this
        # becomes a bottleneck we can set up a long-lived backend queue and
        # use correlation_id to deal with concurrent RPC calls. See:
        #   http://www.rabbitmq.com/tutorials/tutorial-six-python.html
        msg_id = uuid.uuid4().hex

        # expire the reply queue shortly after the timeout. it will be
        # (lazily) deleted by the broker if we don't clean it up first
        queue_arguments = {'x-expires': int((timeout + 1) * 1000)}
        queue = Queue(name=msg_id, exchange=self._exchange, routing_key=msg_id,
                      durable=False, queue_arguments=queue_arguments)

        messages = []
        event = threading.Event()

        def _callback(body, message):
            messages.append(body)
            message.ack()
            event.set()

        d = dict(op=operation, args=args)
        headers = {'reply-to': msg_id, 'sender': self.add_sysname(self.name)}
        dest = self.add_sysname(name)

        def _declare_and_send(channel):
            consumer = Consumer(channel, (queue,), callbacks=(_callback,))
            with Producer(channel) as producer:
                producer.publish(d, routing_key=dest, headers=headers,
                    exchange=self._exchange, serializer=self._serializer)
            return consumer

        log.debug("sending call to %s:%s", dest, operation)
        with connections[self._pool_conn].acquire(block=True) as conn:
            consumer, channel = self.ensure(conn, _declare_and_send)
            try:
                self._consume(conn, consumer, timeout=timeout, until_event=event)

                # try to delete queue, but don't worry if it fails (will expire)
                try:
                    queue = queue.bind(channel)
                    queue.delete(nowait=True)
                except Exception:
                    log.exception("error deleting queue")

            finally:
                conn.maybe_close_channel(channel)

        msg_body = messages[0]
        if msg_body.get('error'):
            raise_error(msg_body['error'])
        else:
            return msg_body.get('result')
开发者ID:lelou6666,项目名称:dashi,代码行数:74,代码来源:__init__.py


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