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


Python kombu.Consumer方法代码示例

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


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

示例1: consume

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def consume(self, queue_name, callback, check=True, connection_kwargs={}):
        queue = self.__queue(queue_name)
        log.debug("Consuming queue '%s'", queue)
        callbacks = [self.__ack_callback]
        if callback is not None:
            callbacks.append(callback)
        while check:
            heartbeat_thread = None
            try:
                with self.connection(self.__url, heartbeat=DEFAULT_HEARTBEAT, **connection_kwargs) as connection:
                    with kombu.Consumer(connection, queues=[queue], callbacks=callbacks, accept=['json']):
                        heartbeat_thread = self.__start_heartbeat(queue_name, connection)
                        while check and connection.connected:
                            try:
                                connection.drain_events(timeout=self.__timeout)
                            except socket.timeout:
                                pass
            except (IOError, socket.error) as exc:
                self.__handle_io_error(exc, heartbeat_thread)
            except BaseException:
                log.exception("Problem consuming queue, consumer quitting in problematic fashion!")
                raise
        log.info("Done consuming queue %s" % queue_name) 
开发者ID:galaxyproject,项目名称:pulsar,代码行数:25,代码来源:amqp_exchange.py

示例2: test

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def test(url):
    from kombu import Exchange, Queue, Connection, Consumer, Producer
    task_queue = Queue('tasks', exchange=Exchange('celery', type='direct'), routing_key='tasks')
    # 生产者
    with Connection(url) as conn:
        with conn.channel() as channel:
            producer = Producer(channel)
            producer.publish({'hello': 'world'},
                             retry=True,
                             exchange=task_queue.exchange,
                             routing_key=task_queue.routing_key,
                             declare=[task_queue])

    def get_message(body, message):
        print("receive message: %s" % body)
        # message.ack()

    # 消费者
    with Connection(url) as conn:
        with conn.channel() as channel:
            consumer = Consumer(channel, queues=task_queue, callbacks=[get_message, ], prefetch_count=10)
            consumer.consume(no_ack=True) 
开发者ID:DataIntegrationAlliance,项目名称:data_integration_celery,代码行数:24,代码来源:check.py

示例3: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def __init__(self, logs, connection, name, exchange, routing_key, queue_name):
        self.__logs = logs
        self.__ignore_some_stuff = False
        self.name = name
        self.__event_callbacks = []
        if queue_name is None:
            queue_name = ''
            exclusive = True
        else:
            exclusive = False
        chan = connection.channel()
        ex = Exchange(exchange, 'topic', channel=chan)
        queue = Queue(exchange=ex, routing_key=routing_key, exclusive=exclusive)
        consumer = Consumer(chan, queues=[queue], callbacks=[self.__message_cb])
        consumer.consume()
        self.exchange = ex 
开发者ID:RackHD,项目名称:RackHD,代码行数:18,代码来源:amqp_source.py

示例4: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def get_consumers(self, _, default_channel):
        queues = [
            Queue(preprocessor.routing_key, exchange=raw_events_exchange,
                  routing_key=preprocessor.routing_key, durable=True)
            for routing_key, preprocessor in self.preprocessors.items()
        ]
        return [Consumer(default_channel,
                         queues=queues,
                         accept=['json'],
                         callbacks=[self.do_preprocess_raw_event])] 
开发者ID:zentralopensource,项目名称:zentral,代码行数:12,代码来源:kombu.py

示例5: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def get_consumers(self, Consumer, channel):
        return [
            Consumer(self.queues, callbacks=[self.on_message]),
        ]

    # 接收处理消息的回调函数 
开发者ID:DataIntegrationAlliance,项目名称:data_integration_celery,代码行数:8,代码来源:check.py

示例6: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def get_consumers(self, Consumer, channel):
        """
        Returns a list of kombu.Consumer instances to service all registered
        notification callbacks.

        If using the kombu.mixin.ConsumerMixin mixin class, these instances
        should be included in its get_consumers() method.

        :param Consumer: Message consumer class.
        :type Consumer: class
        :param channel: An open channel.
        :type channel: kombu.transport.*.Channel
        :returns: A list of consumer instances
        :rtype: [kombu.Consumer, ....]
        """
        consumer_list = []
        exchange = self.bus_mixin.producer.exchange
        for routing_key, callbacks in self.notify_callbacks.items():
            queue = kombu.Queue(
                exchange=exchange, routing_key=routing_key)
            consumer = Consumer(
                queues=queue, callbacks=callbacks)
            consumer_list.append(consumer)
            self.bus_mixin.logger.info(
                'Listening for "%s" notifications', routing_key)
        return consumer_list 
开发者ID:projectatomic,项目名称:commissaire,代码行数:28,代码来源:client.py

示例7: setUp

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Consumer [as 别名]
def setUp(self):
        super(BaseRetryHandlerIntegrationTest, self).setUp()

        # NOTE:
        # must be a real rabbitmq instance, we rely on rabbitmq
        # features (dead-letter exchange) for our retry queue logic
        self.connection = kombu.Connection(
            settings.BROKER_URL,
            connect_timeout=1,
        )
        self.connection.ensure_connection()
        self.connection.connect()
        self.channel = self.connection.channel()

        self.handler = AMQPRetryHandler(
            self.channel,
            routing_key=self.routing_key,
            queue=self.routing_key,
            exchange=self.exchange,
            queue_arguments={},
            func=lambda body: None,
            backoff_func=lambda attempt: 0,
        )
        self.handler.declare_queues()

        queues = [
            self.handler.worker_queue,
            self.handler.retry_queue,
            self.handler.archive_queue,
        ]
        for queue in queues:
            queue.purge()

        self.archive_consumer = kombu.Consumer(
            channel=self.channel,
            queues=[self.handler.archive_queue],
            callbacks=[self.handle_archive]
        )

        for consumer in [self.handler.consumer, self.archive_consumer]:
            consumer.consume()

        self.producer = kombu.Producer(
            self.channel,
            exchange=self.handler.exchanges[self.handler.exchange],
            routing_key=self.routing_key,
            serializer='json'
        )
        self.archives = [] 
开发者ID:depop,项目名称:celery-message-consumer,代码行数:51,代码来源:base.py


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