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


Python kombu.Connection方法代码示例

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


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

示例1: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def __init__(self, name, url="amqp://", maxsize=0, lazy_limit=True):
        """
        Constructor for KombuQueue

        url:        http://kombu.readthedocs.org/en/latest/userguide/connections.html#urls
        maxsize:    an integer that sets the upperbound limit on the number of
                    items that can be placed in the queue.
        """
        self.name = name
        self.conn = Connection(url)
        self.queue = self.conn.SimpleQueue(self.name, no_ack=True, serializer='umsgpack')

        self.maxsize = maxsize
        self.lazy_limit = lazy_limit
        if self.lazy_limit and self.maxsize:
            self.qsize_diff_limit = int(self.maxsize * 0.1)
        else:
            self.qsize_diff_limit = 0
        self.qsize_diff = 0 
开发者ID:binux,项目名称:pyspider,代码行数:21,代码来源:kombu_queue.py

示例2: check_if_celery_available

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def check_if_celery_available():
    result = None
    try:
        conn = Connection(settings.CELERY_BROKER_URL)
        conn.ensure_connection(max_retries=2)
    except Exception as e:
        logger.warning(_("Unable to connect to a celery broker"))
        return False
    inspect = app.control.inspect()
    for i in range(4):
        try:
            result = inspect.ping()
            break
        except BrokenPipeError as e:
            time.sleep(0.10)
            logger.warning(_("Celery worker connection failed. Reattempting"))
            if i == 3:
                logger.warning(_("Failed to connect to celery due to a BrokenPipeError"))
                logger.exception(e)
    if result is None:
        logger.info(_("A celery broker is running, but a celery worker is not available"))
        result = False  # ping returns True or None, assigning False here so we return only a boolean value
    else:
        result = True
    return result 
开发者ID:archesproject,项目名称:arches,代码行数:27,代码来源:task_management.py

示例3: test

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

示例4: start_listener

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

示例5: __init__

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

示例6: start

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def start(self):
        self._browsing_threads = set()
        self._browsing_threads_lock = threading.Lock()

        self._exchange = kombu.Exchange(name=self.exchange_name, type='direct',
                durable=True)

        self._reconnect_requested = False

        self._producer = None
        self._producer_lock = threading.Lock()
        with self._producer_lock:
            self._producer_conn = kombu.Connection(self.amqp_url)
            self._producer = self._producer_conn.Producer(serializer='json')

        self._consumer_thread = threading.Thread(target=self._consume_amqp, name='AmqpConsumerThread')
        self._consumer_stop = threading.Event()
        self._consumer_thread.start() 
开发者ID:internetarchive,项目名称:umbra,代码行数:20,代码来源:controller.py

示例7: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def __init__(self,
                 address,
                 name,
                 transport_options,
                 ssl=False,
                 no_ack=True,
                 queue_opts=None,
                 exchange_opts=None):
        from kombu import Connection
        self._address = address
        self._conn = Connection(address,
                                transport_options=transport_options,
                                ssl=ssl)
        self._queue = self._conn.SimpleQueue(name, no_ack, queue_opts, exchange_opts)
        self._no_ack = no_ack
        self._last_msg = None 
开发者ID:i2y,项目名称:mochi,代码行数:18,代码来源:mailbox.py

示例8: setup_rabbitmq_client

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

示例9: __init__

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

示例10: __init__

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

示例11: start_sync

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

示例12: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def __init__(self):
        self.connection = Connection(settings.CELERY_LOG_BROKER_URL) 
开发者ID:KubeOperator,项目名称:KubeOperator,代码行数:4,代码来源:logger.py

示例13: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def __init__(self, broker, interval=1):
        # self.interval = interval
        self.state = app.events.State()
        self.statsd_conn = StatsClient(host='localhost', port=8125)
        self.broker_conn = BrokerConnection(broker)
        self.timers_list = []

    # monitor the task and status of worker with functions 
开发者ID:adrianyoung,项目名称:CrawlerMonitor,代码行数:10,代码来源:monitor.py

示例14: broker_conn

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def broker_conn():
    """
    A Kombu connection object. Connect with RabbitMQ or Redis.
    """
    connection = Connection("pyamqp://guest:guest@localhost:5672//")
    # connection = Connection("redis://127.0.0.1:6379")
    return connection 
开发者ID:bomquote,项目名称:transistor,代码行数:9,代码来源:conftest.py

示例15: main

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Connection [as 别名]
def main():
    disconnect()
    connect('zhihulive')
    with Connection(BROKER_URI) as conn:
        consumer(conn, [process_task]) 
开发者ID:dongweiming,项目名称:daenerys,代码行数:7,代码来源:worker.py


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