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


Python kombu.Exchange方法代码示例

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


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

示例1: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Exchange [as 别名]
def get_consumers(self, Consumer, channel):

        exchange = Exchange(
            name=OPTIONS['amqp_topic'],
            type='fanout',
            channel=self.channel,
            durable=True
        )

        queues = [
            Queue(
                name=OPTIONS['amqp_queue_name'],
                exchange=exchange,
                routing_key='',
                channel=self.channel,
                exclusive=OPTIONS['amqp_queue_exclusive']
            )
        ]

        return [
            Consumer(queues=queues, accept=['json'],
                     callbacks=[self.on_message])
        ] 
开发者ID:alerta,项目名称:alerta-contrib,代码行数:25,代码来源:mailer.py

示例2: get_consumers

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Exchange [as 别名]
def get_consumers(self, Consumer, channel):
        exchange = Exchange(
            name=AMQP_TOPIC,
            type='fanout',
            channel=self.channel,
            durable=True
        )
        queues = [
            Queue(
                name='',
                exchange=exchange,
                routing_key='',
                channel=self.channel,
                exclusive=True
            )
        ]
        return [
            Consumer(queues=queues, accept=['json'], callbacks=[self.on_message])
        ] 
开发者ID:alerta,项目名称:alerta-contrib,代码行数:21,代码来源:listener.py

示例3: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Exchange [as 别名]
def __init__(self, name=None):
        if app.config['DEBUG']:
            setup_logging(loglevel='DEBUG', loggers=[''])

        self.connection = BrokerConnection(AMQP_URL)
        try:
            self.connection.connect()
        except Exception as e:
            LOG.error('Failed to connect to AMQP transport %s: %s', AMQP_URL, e)
            raise RuntimeError

        self.channel = self.connection.channel()
        self.exchange_name = AMQP_TOPIC

        self.exchange = Exchange(name=self.exchange_name, type='fanout', channel=self.channel)
        self.producer = Producer(exchange=self.exchange, channel=self.channel)

        super(FanoutPublisher, self).__init__(name)

        LOG.info('Configured fanout publisher on topic "%s"', AMQP_TOPIC) 
开发者ID:alerta,项目名称:alerta-contrib,代码行数:22,代码来源:alerta_amqp.py

示例4: test

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

示例5: start_listener

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

示例6: __init__

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

示例7: start

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

示例8: setup_rabbitmq_client

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

示例10: connect

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

示例11: _publish

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Exchange [as 别名]
def _publish(self, event, model_instance):
        """
        Internal function to publish "created", "deleted", and "updated"
        notification messages.

        :param event: The event name ("created", "deleted", or "updated")
        :type event: str
        :param model_instance: The model instance upon which the event occurred
        :type model_instance: commissaire.model.Model
        """
        class_name = model_instance.__class__.__name__
        body = {
            'event': event,
            'class': class_name,
            'model': model_instance.to_dict_safe()
        }
        routing_key = 'notify.storage.{}.{}'.format(class_name, event)
        if self._producer:
            self.logger.debug('Publish "{}": {}'.format(routing_key, body))
            self._producer.publish(
                body, routing_key,
                kombu.Exchange.TRANSIENT_DELIVERY_MODE)
        else:
            # This means the connect() method was not called.
            self.logger.warn('Not publishing "%s"', routing_key) 
开发者ID:projectatomic,项目名称:commissaire,代码行数:27,代码来源:notify.py

示例12: __init__

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

示例13: __init__

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

示例14: start_sync

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

示例15: __init__

# 需要导入模块: import kombu [as 别名]
# 或者: from kombu import Exchange [as 别名]
def __init__(self, trackers: List[str], exchange_name: str='transistor',
                 exchange_type: str='direct'):
        self.trackers = trackers
        self.exchange_name = exchange_name
        self.exchange_type = exchange_type
        self.task_exchange = Exchange(self.exchange_name, type=self.exchange_type)
        self.task_queues = []
        self._init_task_queues() 
开发者ID:bomquote,项目名称:transistor,代码行数:10,代码来源:queues.py


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