本文整理汇总了Python中kombu.connection.BrokerConnection.get_transport_cls方法的典型用法代码示例。如果您正苦于以下问题:Python BrokerConnection.get_transport_cls方法的具体用法?Python BrokerConnection.get_transport_cls怎么用?Python BrokerConnection.get_transport_cls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.connection.BrokerConnection
的用法示例。
在下文中一共展示了BrokerConnection.get_transport_cls方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connection
# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import get_transport_cls [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()