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


Python kombu.Exchange类代码示例

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


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

示例1: test_assert_is_bound

    def test_assert_is_bound(self):
        exchange = Exchange('foo', 'direct')
        with pytest.raises(NotBoundError):
            exchange.declare()
        conn = get_conn()

        chan = conn.channel()
        exchange.bind(chan).declare()
        assert 'exchange_declare' in chan
开发者ID:celery,项目名称:kombu,代码行数:9,代码来源:test_entity.py

示例2: test_assert_is_bound

    def test_assert_is_bound(self):
        exchange = Exchange('foo', 'direct')
        with self.assertRaises(NotBoundError):
            exchange.declare()
        conn = get_conn()

        chan = conn.channel()
        exchange.bind(chan).declare()
        self.assertIn('exchange_declare', chan)
开发者ID:1995rishi,项目名称:flaskmap,代码行数:9,代码来源:test_entities.py

示例3: test_eq

    def test_eq(self):
        e1 = Exchange('foo', 'direct')
        e2 = Exchange('foo', 'direct')
        self.assertEqual(e1, e2)

        e3 = Exchange('foo', 'topic')
        self.assertNotEqual(e1, e3)

        self.assertEqual(e1.__eq__(True), NotImplemented)
开发者ID:1995rishi,项目名称:flaskmap,代码行数:9,代码来源:test_entities.py

示例4: test_eq

    def test_eq(self):
        e1 = Exchange('foo', 'direct')
        e2 = Exchange('foo', 'direct')
        assert e1 == e2

        e3 = Exchange('foo', 'topic')
        assert e1 != e3

        assert e1.__eq__(True) == NotImplemented
开发者ID:celery,项目名称:kombu,代码行数:9,代码来源:test_entity.py

示例5: test_bound

    def test_bound(self):
        exchange = Exchange('foo', 'direct')
        assert not exchange.is_bound
        assert '<unbound' in repr(exchange)

        chan = get_conn().channel()
        bound = exchange.bind(chan)
        assert bound.is_bound
        assert bound.channel is chan
        assert 'bound to chan:%r' % (chan.channel_id,) in repr(bound)
开发者ID:celery,项目名称:kombu,代码行数:10,代码来源:test_entity.py

示例6: test_bound

    def test_bound(self):
        exchange = Exchange('foo', 'direct')
        self.assertFalse(exchange.is_bound)
        self.assertIn('<unbound', repr(exchange))

        chan = get_conn().channel()
        bound = exchange.bind(chan)
        self.assertTrue(bound.is_bound)
        self.assertIs(bound.channel, chan)
        self.assertIn('bound to chan:%r' % (chan.channel_id, ),
                      repr(bound))
开发者ID:1995rishi,项目名称:flaskmap,代码行数:11,代码来源:test_entities.py

示例7: connect_to_amqp

def connect_to_amqp(sysconfig):
    """
    Connect to an AMQP Server, and return the connection and Exchange.
    :param sysconfig: The slickqaweb.model.systemConfiguration.amqpSystemConfiguration.AMQPSystemConfiguration instance
                      to use as the source of information of how to connect.
    :return: (connection, exchange) on success, exception on error
    """
    assert isinstance(sysconfig, AMQPSystemConfiguration)
    configuration = dict()
    configuration['AMQP'] = dict()
    if hasattr(sysconfig, 'hostname') and sysconfig.hostname is not None:
        configuration['AMQP']['hostname'] = sysconfig.hostname
    else:
        raise AMQPConnectionError(message="No hostname defined for AMQP connection.")
    if hasattr(sysconfig, 'port') and sysconfig.port is not None:
        configuration['AMQP']['port'] = sysconfig.port
    if hasattr(sysconfig, 'username') and sysconfig.username is not None:
        configuration['AMQP']['username'] = sysconfig.username
    if hasattr(sysconfig, 'password') and sysconfig.password is not None:
        configuration['AMQP']['password'] = sysconfig.password
    if hasattr(sysconfig, 'virtualHost') and sysconfig.virtualHost is not None:
        configuration['AMQP']['virtual host'] = sysconfig.virtualHost
    if hasattr(sysconfig, 'exchangeName') and sysconfig.exchangeName is not None:
        configuration['AMQP']['exchange'] = sysconfig.exchangeName
    else:
        raise AMQPConnectionError(message="No exchange defined for AMQP connection.")

    logger = logging.getLogger("slickqaweb.amqpcon.connect_to_amqp")

    url = str.format("amqp://{hostname}:{port}", **dict(list(configuration['AMQP'].items())))
    if 'virtual host' in configuration['AMQP'] and configuration['AMQP']['virtual host'] != '':
        url = str.format("{}/{}", url, configuration['AMQP']['virtual host'])
    logger.debug("AMQPConnection configured with url %s", url)
    exchange = Exchange(configuration['AMQP'].get('exchange', "amqp.topic"), type='topic', durable=True)
    logger.debug("AMQPConnection is using exchange %s", exchange)
    connection = None
    if 'username' in configuration['AMQP'] and 'password' in configuration['AMQP']:
        username = configuration['AMQP']['username']
        password = configuration['AMQP']['password']
        logger.debug("Using username %s and password %s to connect to AMQP Broker", username, password)
        connection = Connection(url, userid=username, password=password)
    else:
        connection = Connection(url)

    # typically connection connect on demand, but we want to flush out errors before proceeding
    connection.connect()
    exchange = exchange(connection)
    exchange.declare()
    return (connection, exchange)
开发者ID:slickqa,项目名称:slickqaweb,代码行数:49,代码来源:amqpcon.py

示例8: __init__

 def __init__(self, url, exchange_name=None):
     self.url = url
     self.connect()
     self.exchange_name = exchange_name if exchange_name else celery_queue('socket_notification')
     self.channel = self.connection.channel()
     self.socket_exchange = Exchange(self.exchange_name, type='fanout', channel=self.channel)
     self.socket_exchange.declare()
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:7,代码来源:websockets_comms.py

示例9: test_revive

    def test_revive(self):
        exchange = Exchange('foo', 'direct')
        conn = get_conn()
        chan = conn.channel()

        # reviving unbound channel is a noop.
        exchange.revive(chan)
        assert not exchange.is_bound
        assert exchange._channel is None

        bound = exchange.bind(chan)
        assert bound.is_bound
        assert bound.channel is chan

        chan2 = conn.channel()
        bound.revive(chan2)
        assert bound.is_bound
        assert bound._channel is chan2
开发者ID:celery,项目名称:kombu,代码行数:18,代码来源:test_entity.py

示例10: test_revive

    def test_revive(self):
        exchange = Exchange('foo', 'direct')
        conn = get_conn()
        chan = conn.channel()

        # reviving unbound channel is a noop.
        exchange.revive(chan)
        self.assertFalse(exchange.is_bound)
        self.assertIsNone(exchange._channel)

        bound = exchange.bind(chan)
        self.assertTrue(bound.is_bound)
        self.assertIs(bound.channel, chan)

        chan2 = conn.channel()
        bound.revive(chan2)
        self.assertTrue(bound.is_bound)
        self.assertIs(bound._channel, chan2)
开发者ID:1995rishi,项目名称:flaskmap,代码行数:18,代码来源:test_entities.py

示例11: broker

class SocketBrokerClient:
    """
    Base class for web socket notification using broker (redis or rabbitmq)
    """

    connection = None

    def __init__(self, url, exchange_name=None):
        self.url = url
        self.connect()
        self.exchange_name = exchange_name if exchange_name else celery_queue('socket_notification')
        self.channel = self.connection.channel()
        self.socket_exchange = Exchange(self.exchange_name, type='fanout', channel=self.channel)
        self.socket_exchange.declare()

    def open(self):
        """Test if connection is open.

        True if connected else false

        :return bool:
        """
        return self.connection and self.connection.connected

    def connect(self):
        self._close()
        logger.info('Connecting to broker {}'.format(self.url))
        self.connection = Connection(self.url, heartbeat=WS_HEART_BEAT)
        self.connection.connect()
        logger.info('Connected to broker {}'.format(self.url))

    def _close(self):
        if hasattr(self, 'connection') and self.connection:
            logger.info('Closing connecting to broker {}'.format(self.url))
            self.connection.release()
            self.connection = None
            logger.info('Connection closed to broker {}'.format(self.url))

    def close(self):
        self._close()
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:40,代码来源:websockets_comms.py

示例12: broker

class SocketBrokerClient:
    """
    Base class for web socket notification using broker (redis or rabbitmq)

    """

    connection = None

    def __init__(self, url):
        self.url = url
        self.connect()
        self.channel = self.connection.channel()
        self.socket_exchange = Exchange(exchange_name, type="fanout", channel=self.channel)
        self.socket_exchange.declare()

    def open(self):
        """
        True if connected else false
        :return bool:
        """
        return self.connection and self.connection.connected

    def connect(self):
        self._close()
        logger.info("Connecting to broker {}".format(self.url))
        self.connection = Connection(self.url)
        self.connection.connect()
        logger.info("Connected to broker {}".format(self.url))

    def _close(self):
        if hasattr(self, "connection") and self.connection:
            logger.info("Closing connecting to broker {}".format(self.url))
            self.connection.release()
            self.connection = None
            logger.info("Connection closed to broker {}".format(self.url))

    def close(self):
        self._close()
开发者ID:akintolga,项目名称:superdesk-core,代码行数:38,代码来源:websockets_comms.py

示例13: declare_exchange

    def declare_exchange(self, name, type='direct', queues=None, **options):
        """Create or update exchange

        :param name: name of exchange
        :type name: str
        :param type: type of exchange - direct, fanout, topic, match
        :type type: str
        :param queues: list of queues with routing keys: [[queue_name, routing_key], [queue_name, routing_key], ...]
        :type queues: list, None or tuple
        :param options: additional options for Exchange creation
        """
        if queues is None:
            queues = []

        with connections[self.connection].acquire() as conn:
            exchange = Exchange(name, type=type, channel=conn, **options)
            exchange.declare()
            self.exchanges[name] = exchange
            for q_name, routing_key in queues:
                queue = Queue(name=q_name, channel=conn)
                queue.declare()
                queue.bind_to(exchange=name, routing_key=routing_key)
                self.logger.debug('Queue "%s" with routing_key "%s" was bond to exchange "%s"', q_name,
                                  routing_key if routing_key else q_name, name)
开发者ID:aclef,项目名称:microservices,代码行数:24,代码来源:client.py

示例14: connect

    def connect(self):
        if not self.connection:
            logging.info("Connecting to server %s", self.amqp_address)
            self.connection = self.create_connection()
        else:
            return

        self.channel = self.connection.channel()
        self.channel.basic_qos(0, self.prefetch_count, False)

        for qname, params in self.queues.iteritems():
            if "exchange" in params:
                exchange = Exchange(params["exchange"], **self.exchanges.get(params["exchange"], {}))
                exchange = exchange(self.channel)
                exchange.declare()
                self.declared_exchanges[params["exchange"]] = exchange

                queue_params = params.copy()
                del queue_params['exchange']
                self.declared_queues[qname] = Queue(qname, exchange=exchange, **queue_params)
            else:
                self.declared_queues[qname] = Queue(qname, **params)

            self.declared_queues[qname](self.channel).declare()
开发者ID:eiwill,项目名称:backend,代码行数:24,代码来源:amqp_client.py

示例15: KWriteQueue

class KWriteQueue(object):
    def __init__(self, channel, exchange, **kwargs):
        self._exchange_declare = kwargs.get("exchange_declare", False)
        if isinstance(exchange, Queue):
            self.exchange = exchange.exchange
        elif isinstance(exchange, basestring):
            self.exchange = Exchange(exchange, type="fanout")  # , durable=True)
        else:
            assert isinstance(exchange, Exchange)
            self.exchange = exchange
        self.channel = maybe_channel(channel)
        self.exchange.maybe_bind(self.channel)
        if self._exchange_declare:
            self.exchange.declare()

        self.producer = messaging.Producer(channel, self.exchange,
                                           serializer='json',
                                           routing_key='',
                                           compression=None,
                                           auto_declare=False)

    def __enter__(self):
        return self

    def __exit__(self, *exc_info):
        self.close()

    def put(self, message, serializer=None, headers=None, compression=None,
            routing_key=None, **kwargs):
        self.producer.publish(message,
                              content_type="application/octet-stream",
                              serializer=serializer,
                              routing_key=routing_key,
                              headers=headers,
                              compression=compression,
                              **kwargs)
开发者ID:runninghack,项目名称:twitter-geo,代码行数:36,代码来源:kqueue.py


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