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


Python kombu.Queue方法代码示例

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


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

示例1: test

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [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

示例2: start_listener

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def start_listener(runtime_context):
    # Need to keep the amqp logger level at least as high as INFO,
    # or else it send heartbeat check messages every second
    logging.getLogger('amqp').setLevel(max(logger.level, getattr(logging, 'INFO')))
    logger.info('Starting pipeline listener')

    fits_exchange = Exchange(runtime_context.FITS_EXCHANGE, type='fanout')
    listener = RealtimeModeListener(runtime_context)

    with Connection(runtime_context.broker_url) as connection:
        listener.connection = connection.clone()
        listener.queue = Queue(runtime_context.queue_name, fits_exchange)
        try:
            listener.run()
        except listener.connection.connection_errors:
            listener.connection = connection.clone()
            listener.ensure_connection(max_retries=10)
        except KeyboardInterrupt:
            logger.info('Shutting down pipeline listener.') 
开发者ID:LCOGT,项目名称:banzai,代码行数:21,代码来源:main.py

示例3: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __init__(self, crawl_name, num_urls=DEFAULT_NUM_URLS):
        """
        Create a NutchUrlTrails instance for visualizing a running Nutch crawl in real-time using Bokeh
        :param name: The name of the crawl (as identified by the queue)
        :param num_urls: The number of URLs to display in the visualization
        :return: A NutchUrLTrails instance
        """
        self.crawl_name = crawl_name
        self.num_urls = num_urls
        self.open_urls = {}
        self.closed_urls = {}
        self.old_segments = None
        self.old_circles = None
        
        self.session = Session()
        self.session.use_doc(self.crawl_name)
        self.document = Document()

        con = Connection()

        exchange = Exchange(EXCHANGE_NAME, 'direct', durable=False)
        queue = Queue(crawl_name, exchange=exchange, routing_key=crawl_name)
        self.queue = con.SimpleQueue(name=queue) 
开发者ID:nasa-jpl-memex,项目名称:memex-explorer,代码行数:25,代码来源:stream.py

示例4: setup_rabbitmq_client

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def setup_rabbitmq_client(options):
    global RABBITMQ_CLIENT
    try:
        RABBITMQ_CLIENT
    except NameError:
        mqConnString = 'amqp://{0}:{1}@{2}:{3}//'.format(
            options.mquser,
            options.mqpassword,
            options.mqalertserver,
            options.mqport
        )
        mqAlertConn = Connection(mqConnString)
        alertExchange = Exchange(name=options.alertExchange, type='topic', durable=True, delivery_mode=1)
        alertExchange(mqAlertConn).declare()

        alertQueue = Queue(options.queueName,
                           exchange=alertExchange,
                           routing_key=options.alerttopic,
                           durable=False,
                           no_ack=(not options.mqack))
        alertQueue(mqAlertConn).declare()

        RABBITMQ_CLIENT = mqAlertConn.Consumer(alertQueue, accept=['json'])
    return RABBITMQ_CLIENT 
开发者ID:mozilla,项目名称:MozDef,代码行数:26,代码来源:suite_helper.py

示例5: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [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

示例6: connect

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def connect(self, exchange, channel):  # pragma: no cover
        """
        Readies the StorageNotify for publishing notification messages by
        setting up a kombu.Producer.

        :param exchange: The exchange for publishing notifications.
        :type exchange: kombu.Exchange
        :param channel: The channel to bind to.
        :type channel: kombu.transport.base.StdChannel
        """
        name = self.__class__.__name__
        self.logger.debug('Connecting {}'.format(name))

        self._queue = kombu.Queue(exchange=exchange, channel=channel)
        self._queue.declare()

        self._producer = kombu.Producer(channel, exchange) 
开发者ID:projectatomic,项目名称:commissaire,代码行数:19,代码来源:notify.py

示例7: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __init__(self, connection, socket, ns_name):
        self.connection = connection
        self.socket = socket
        self.ns_name = ns_name
        self.queue = Queue(
            'notifications-{}'.format(uuid.uuid1()),
            exchange=notifications_exchange,
            routing_key='notifications',
            auto_delete=True
        ) 
开发者ID:abarto,项目名称:tracker_project,代码行数:12,代码来源:sockets.py

示例8: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __init__(self, env, is_external_queue: bool):
        super().__init__(env, is_external_queue, queue_type='redis', logger=logger)

        conf = env.config

        bind_port = self.get_port()
        if bind_port is None:
            logger.info('skipping pubsub setup, no port specified')
            return

        queue_host = conf.get(ConfigKeys.HOST, domain=self.domain_key, default=None)
        exchange = conf.get(ConfigKeys.EXCHANGE, domain=self.domain_key, default='node_exchange')
        queue_db = conf.get(ConfigKeys.DB, domain=self.domain_key, default=0)
        queue_name = conf.get(ConfigKeys.QUEUE, domain=self.domain_key, default=None)

        if queue_name is None or len(queue_name.strip()) == 0:
            queue_name = 'node_queue_%s_%s_%s' % (
                conf.get(ConfigKeys.ENVIRONMENT),
                self.get_host(),
                bind_port
            )

        if self.is_external_queue:
            self.exchange = Exchange(exchange, type='direct')
        else:
            self.exchange = Exchange(exchange, type='fanout')

        self.queue_connection = Connection(queue_host, transport_options={'db': queue_db})
        logger.info('queue connection: {}'.format(str(self.queue_connection)))
        self.queue_name = queue_name
        self.queue = Queue(self.queue_name, self.exchange) 
开发者ID:thenetcircle,项目名称:dino,代码行数:33,代码来源:redis.py

示例9: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __init__(self, _conf):
        amqp_conf = conf.get(ConfigKeys.AMQP)
        queue_host = amqp_conf.get(ConfigKeys.HOST)
        if queue_host is None or len(queue_host.strip()) == 0:
            return

        queue_port = amqp_conf.get(ConfigKeys.PORT)
        queue_vhost = amqp_conf.get(ConfigKeys.VHOST)
        queue_user = amqp_conf.get(ConfigKeys.USER)
        queue_pass = amqp_conf.get(ConfigKeys.PASSWORD)

        queue_host = ';'.join(['amqp://%s' % host for host in queue_host.split(';')])
        queue_exchange = '%s_%s' % (
            amqp_conf.get(ConfigKeys.EXCHANGE),
            amqp_conf.get(ConfigKeys.ENVIRONMENT)
        )

        queue_name = amqp_conf.get(ConfigKeys.QUEUE)
        self.exchange = Exchange(queue_exchange, type='direct')

        self.queue_connection = Connection(
            hostname=queue_host,
            port=queue_port,
            virtual_host=queue_vhost,
            userid=queue_user,
            password=queue_pass
        )
        self.queue = Queue(queue_name, self.exchange)
        logger.info('setting up pubsub for host(s) "{}"'.format(queue_host)) 
开发者ID:thenetcircle,项目名称:dino,代码行数:31,代码来源:kafka_to_rabbitmq.py

示例10: start_sync

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def start_sync(self):
        exchange = Exchange(self.exchange_name, self.exchange_type, durable=self.durable)
        queue = Queue(self.queue_name, exchange=exchange, routing_key=self.routing_key)
        with Connection(self.amqp_url) as conn:
            # producer = conn.Producer(serializer='json')
            # producer.publish({'name': '/tmp/lolcat1.avi', 'size': 1301013},
            #                  exchange=exchange, routing_key=self.routing_key,
            #                  declare=[queue])
            # producer.publish({'name': '/tmp/lolcat1.avi', 'size': 1301013},
            #                  exchange=exchange, routing_key=self.routing_key,
            #                  declare=[queue])
            with conn.Consumer(queue, callbacks=[self.rabbitmq_callback]) as consumer:
                # Process messages and handle events on all channels
                while True:
                    conn.drain_events() 
开发者ID:threathunterX,项目名称:sniffer,代码行数:17,代码来源:rabbitmqdriver.py

示例11: _init_task_queues

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def _init_task_queues(self):
        """
        Assuming we init with parameter `trackers = ['mousekey.com', 'digidog.com',
        'futuredigi.com']`
        then this should set self.task_queues as below:

        self.task_queues = [
           Queue('mousekey.com', task_exchange, routing_key='mousekey.com'),
           Queue('digidog.com', task_exchange, routing_key='digidog.com'),
           Queue('futuredigi.com', task_exchange, routing_key='futuredigi.com')]
        """
        for tracker_name in self.trackers:
            queue = Queue(tracker_name, self.task_exchange, routing_key=tracker_name)
            self.task_queues.append(queue) 
开发者ID:bomquote,项目名称:transistor,代码行数:16,代码来源:queues.py

示例12: __queue

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __queue(self, name):
        queue_name = self.__queue_name(name)
        queue = kombu.Queue(queue_name, self.__exchange, routing_key=queue_name)
        return queue 
开发者ID:galaxyproject,项目名称:pulsar,代码行数:6,代码来源:amqp_exchange.py

示例13: handle

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def handle(self, queue, *args, **options):
        fmt = '%(asctime)s %(name)-12s: %(levelname)-8s %(message)s'
        log_level = 40 - (options['verbosity'] * 10)
        logging.basicConfig(level=log_level, format=fmt)

        # TODO: Ensure that failed processing does not requeue task into
        # work queue
        set_event_loop(Hub())
        kwargs = {
            'transport_options': conf.broker_transport_options,
        }
        with app.connection(**kwargs) as conn:
            logger.info("Launching worker")
            worker = Worker(conn, queues=[Queue(queue)])
            worker.connect_max_retries = 1
            while True:
                try:
                    breakers.celery.call(worker.run)
                except KeyboardInterrupt:
                    logger.info("KeyboardInterrupt, exiting. Bye!")
                    break
                except breakers.celery.expected_errors:
                    rest_val = 5
                    logger.warning(
                        "Open circuit detected. "
                        "Sleeping for %s seconds and then will try again.",
                        rest_val
                    )
                    time.sleep(rest_val) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:31,代码来源:sync_tasks.py

示例14: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [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

示例15: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Queue [as 别名]
def __init__(self, connection, event_store):
        self.connection = connection
        self.event_store = event_store
        self.name = "store worker {}".format(self.event_store.name)
        self.input_queue = Queue(('store_events_{}'.format(self.event_store.name)).replace(" ", "_"),
                                 exchange=enriched_events_exchange,
                                 durable=True) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:9,代码来源:kombu.py


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