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


Python BrokerConnection.channel方法代码示例

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


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

示例1: connection

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
class RabbitMQConnection:
    def connection(self):
        try:
            logger.info("Connection to the AMQP broker '" + AMQP_IP + ":" + AMQP_PORT + "' ...")
            connection = BrokerConnection(hostname=AMQP_IP,
                                          port=AMQP_PORT,
                                          userid=AMQP_USER,
                                          password=AMQP_PASSWORD,
                                          virtual_host="/",
                                          transport=AMQP_TRANSPORT)
            #channel = connection.channel()
            logger.info("Connection to the AMQP broker established.")
            return connection
        except Exception as exep:
            logger.warning("Could not connect to the AMQP broker '" + AMQP_IP + ":" + AMQP_PORT + "'. | " + str(exep))

    def producer(self):
        self.connection = BrokerConnection(hostname=AMQP_IP, port=AMQP_PORT,
                                           userid=AMQP_USER, password=AMQP_PASSWORD,
                                           virtual_host="/",
                                           transport=AMQP_TRANSPORT)
        self.channel = self.connection.channel()
        # produce

        self.media_exchange = Exchange("media", "direct", durable=True)

        producer = Producer(self.channel, exchange=self.media_exchange, serializer="json")
        producer.publish({"name": "/tmp/lolcat1.avi", "size": 1301013})

        print self.connection.get_transport_cls()

    def consumer(self):
        self.connection = BrokerConnection(hostname=AMQP_IP, port=AMQP_PORT,
                                           userid=AMQP_USER, password=AMQP_PASSWORD,
                                           virtual_host="/")
        self.channel = self.connection.channel()

        # consume

        self.media_exchange = Exchange("media", "direct", durable=True)
        self.video_queue = Queue("video", exchange=self.media_exchange, key="video")

        consumer = Consumer(self.channel, self.video_queue)
        consumer.register_callback(self.process_media)
        consumer.consume()
        # Process messages on all channels
        while True:
            self.connection.drain_events()


    def process_media(self, message_data, message):
        feed_url = message_data["name"]
        print ("Got feed import message for: %s" % feed_url)
        # something importing this feed url
        # import_feed(feed_url)
        message.ack()
开发者ID:occi,项目名称:TSP-CloudStack,代码行数:58,代码来源:connection_amqp.py

示例2: create_connection

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
def create_connection():
    conn = BrokerConnection("localhost",
                            "fred",
                            "fred123",
                            "home")
    channel = conn.channel()
    return channel
开发者ID:lefred,项目名称:centipede,代码行数:9,代码来源:views.py

示例3: test_publish__consume

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
    def test_publish__consume(self):
        connection = BrokerConnection(transport=Transport)
        channel = connection.channel()
        producer = Producer(channel, self.exchange, routing_key="test_Redis")
        consumer = Consumer(channel, self.queue)

        producer.publish({"hello2": "world2"})
        _received = []

        def callback(message_data, message):
            _received.append(message_data)
            message.ack()

        consumer.register_callback(callback)
        consumer.consume()

        self.assertTrue(channel._poller._can_start())
        try:
            connection.drain_events(timeout=1)
            self.assertTrue(_received)
            self.assertFalse(channel._poller._can_start())
            self.assertRaises(socket.timeout,
                              connection.drain_events, timeout=0.01)
        finally:
            channel.close()
开发者ID:abourget,项目名称:kombu,代码行数:27,代码来源:test_transport_pyredis.py

示例4: _do_test

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
 def _do_test():
     conn = BrokerConnection(transport=Transport)
     chan = conn.channel()
     self.assertTrue(chan.Client)
     self.assertTrue(chan.ResponseError)
     self.assertTrue(conn.transport.connection_errors)
     self.assertTrue(conn.transport.channel_errors)
开发者ID:crankycoder,项目名称:zamboni-lib,代码行数:9,代码来源:test_transport_redis.py

示例5: PypoFetch

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
class PypoFetch(Thread):
    def __init__(self, q):
        Thread.__init__(self)
        logger = logging.getLogger('fetch')
        self.api_client = api_client.api_client_factory(config)
        self.set_export_source('scheduler')
        self.queue = q
        logger.info("PypoFetch: init complete")

    def init_rabbit_mq(self):
        logger = logging.getLogger('fetch')
        logger.info("Initializing RabbitMQ stuff")
        try:
            schedule_exchange = Exchange("airtime-schedule", "direct", durable=True, auto_delete=True)
            schedule_queue = Queue("pypo-fetch", exchange=schedule_exchange, key="foo")
            self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
            channel = self.connection.channel()
            consumer = Consumer(channel, schedule_queue)
            consumer.register_callback(handle_message)
            consumer.consume()
        except Exception, e:
            logger.error(e)
            return False
            
        return True
开发者ID:DoghouseMedia,项目名称:Airtime,代码行数:27,代码来源:pypofetch.py

示例6: AirtimeNotifier

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
class AirtimeNotifier(Notifier):

    def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None, airtime_config=None, api_client=None, bootstrap=None, mmc=None):
        Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout)

        self.logger = logging.getLogger()
        self.config = airtime_config
        self.api_client = api_client
        self.bootstrap = bootstrap
        self.md_manager = AirtimeMetadata()
        self.import_processes = {}
        self.watched_folders = []
        self.mmc = mmc
        self.wm = watch_manager
        self.mask = pyinotify.ALL_EVENTS

        while not self.init_rabbit_mq():
            self.logger.error("Error connecting to RabbitMQ Server. Trying again in few seconds")
            time.sleep(5)

    def init_rabbit_mq(self):
        self.logger.info("Initializing RabbitMQ stuff")
        try:
            schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
            schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
            self.connection = BrokerConnection(self.config.cfg["rabbitmq_host"], self.config.cfg["rabbitmq_user"], self.config.cfg["rabbitmq_password"], self.config.cfg["rabbitmq_vhost"])
            channel = self.connection.channel()
            consumer = Consumer(channel, schedule_queue)
            consumer.register_callback(self.handle_message)
            consumer.consume()
        except Exception, e:
            self.logger.error(e)
            return False

        return True
开发者ID:vonloxx,项目名称:Airtime,代码行数:37,代码来源:airtimenotifier.py

示例7: setup_rabbit_mq_channel

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
 def setup_rabbit_mq_channel(self):
     service_exchange = Exchange(self.acord_control_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(self.rabbit_host, self.rabbit_user, self.rabbit_password)
     logging.info("Connection to RabbitMQ server successful")
     channel = connection.channel()
     # produce
     self.producer = Producer(channel, exchange=service_exchange, routing_key='notifications.info')
开发者ID:rdudyala,项目名称:udpagent,代码行数:10,代码来源:udpagent.py

示例8: create_connection

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
def create_connection(config):
    conn = BrokerConnection(config.get("connection", "hostname"),
                                  config.get("connection", "userid"),
                                  config.get("connection", "password"),
                                  config.get("connection", "virtual_host"))
    channel = conn.channel()

    return channel
开发者ID:lefred,项目名称:centipede,代码行数:10,代码来源:connection.py

示例9: AMQPWorker

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
class AMQPWorker(Worker):

    queues = [
        {'routing_key': 'test',
         'name': 'test',
         'handler': 'handle_test'
        }
    ]

    _connection = None

    def handle_test(self, body, message):
        log.debug("Handle message: %s" % body)
        message.ack()

    def handle(self):
        log.debug("Start consuming")
        exchange = Exchange('amqp.topic', type='direct', durable=True)
        self._connection = BrokerConnection(*CONNECTION)
        channel = self._connection.channel()

        for entry in self.queues:
            log.debug("prepare to consume %s" % entry['routing_key'])
            queue = Queue(entry['name'], exchange=exchange,
                          routing_key=entry['routing_key'])
            consumer = Consumer(channel, queue)
            consumer.register_callback(getattr(self, entry['handler']))
            consumer.consume()

        log.debug("start consuming...")
        while True:
            try:
                self._connection.drain_events()
            except socket.timeout:
                log.debug("nothing to consume...")
                break
        self._connection.close()

    def run(self):
        while self.alive:
            try:
                self.handle()
            except Exception:
                self.alive = False
                raise

    def handle_quit(self, sig, frame):
        if self._connection is not None:
            self._connection.close()
        self.alive = False

    def handle_exit(self, sig, frame):
        if self._connection is not None:
            self._connection.close()
        self.alive = False
        sys.exit(0)
开发者ID:alepharchives,项目名称:pistil,代码行数:58,代码来源:amqp.py

示例10: setup_rabbit_mq_channel

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
def setup_rabbit_mq_channel():
     global producer
     global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id
     vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     print 'Connection to RabbitMQ server successful'
     channel = connection.channel()
     # produce
     producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info')
开发者ID:srikanthvavila,项目名称:ceilometer-plugins,代码行数:12,代码来源:sample_event_publisher.py

示例11: init_rabbit_mq

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
 def init_rabbit_mq(self):
     self.logger.info("Initializing RabbitMQ stuff")
     try:
         schedule_exchange = Exchange("airtime-pypo", "direct", durable=True, auto_delete=True)
         schedule_queue = Queue("pypo-fetch", exchange=schedule_exchange, key="foo")
         connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], config["rabbitmq_vhost"])
         channel = connection.channel()
         self.simple_queue = SimpleQueue(channel, schedule_queue)
     except Exception, e:
         self.logger.error(e)
         return False
开发者ID:vonloxx,项目名称:Airtime,代码行数:13,代码来源:pypomessagehandler.py

示例12: setup_rabbit_mq_channel

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
 def setup_rabbit_mq_channel(self):
     service_exchange = Exchange(cfg.CONF.udpservice.acord_control_exchange, "topic", durable=False)
     rabbit_host = cfg.CONF.udpservice.rabbit_hosts
     rabbit_user = cfg.CONF.udpservice.rabbit_userid 
     rabbit_password = cfg.CONF.udpservice.rabbit_password
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     print 'Connection to RabbitMQ server successful'
     channel = connection.channel()
     # produce
     self.producer = Producer(channel, exchange=service_exchange, routing_key='notifications.info')
开发者ID:rdudyala,项目名称:ceilometer_custom_plugin,代码行数:13,代码来源:udpservice.py

示例13: test_establish_connection

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
 def test_establish_connection(self):
     conn = BrokerConnection(port=5672, backend_cls=Backend)
     conn.connect()
     self.assertTrue(conn.connection.connected)
     self.assertEqual(conn.host, "localhost:5672")
     channel = conn.channel()
     self.assertTrue(channel.open)
     self.assertEqual(conn.drain_events(), "event")
     _connection = conn.connection
     conn.close()
     self.assertFalse(_connection.connected)
     self.assertIsInstance(conn.backend, Backend)
开发者ID:bradjasper,项目名称:kombu,代码行数:14,代码来源:test_connection.py

示例14: AirtimeNotifier

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
class AirtimeNotifier(Loggable):
    """
    AirtimeNotifier is responsible for interecepting RabbitMQ messages and
    feeding them to the event_handler object it was initialized with. The only
    thing it does to the messages is parse them from json
    """

    def __init__(self, cfg, message_receiver):
        self.cfg = cfg
        self.handler = message_receiver
        while not self.init_rabbit_mq():
            self.logger.error("Error connecting to RabbitMQ Server. Trying again in few seconds")
            time.sleep(5)

    def init_rabbit_mq(self):
        try:
            self.logger.info("Initializing RabbitMQ message consumer...")
            schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
            schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
            self.connection = BrokerConnection(
                self.cfg["rabbitmq"]["host"],
                self.cfg["rabbitmq"]["user"],
                self.cfg["rabbitmq"]["password"],
                self.cfg["rabbitmq"]["vhost"],
            )
            channel = self.connection.channel()

            self.simple_queue = SimpleQueue(channel, schedule_queue)

            self.logger.info("Initialized RabbitMQ consumer.")
        except Exception as e:
            self.logger.info("Failed to initialize RabbitMQ consumer")
            self.logger.error(e)
            return False

        return True

    def handle_message(self, message):
        """
        Messages received from RabbitMQ are handled here. These messages
        instruct media-monitor of events such as a new directory being watched,
        file metadata has been changed, or any other changes to the config of
        media-monitor via the web UI.
        """
        self.logger.info("Received md from RabbitMQ: %s" % str(message))
        m = json.loads(message)
        # TODO : normalize any other keys that could be used to pass
        # directories
        if "directory" in m:
            m["directory"] = normpath(m["directory"])
        self.handler.message(m)
开发者ID:Robbt,项目名称:Airtime,代码行数:53,代码来源:airtime.py

示例15: setup_rabbit_mq_channel

# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import channel [as 别名]
def setup_rabbit_mq_channel():
     global producer
     global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id
     vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False)
     # connections/channels
     connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
     logger.info('Connection to RabbitMQ server successful')
     channel = connection.channel()
     # produce
     producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info')
     p = subprocess.Popen('hostname', shell=True, stdout=subprocess.PIPE)
     (hostname, error) = p.communicate()
     cpe_publisher_id = cpe_publisher_id + '_on_' + hostname
     logger.info('cpe_publisher_id=%s',cpe_publisher_id)
开发者ID:albertoflorez,项目名称:xos,代码行数:16,代码来源:vcpe_stats_notifier.py


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