當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。