Kombu Exchange

本文地址:http://blog.csdn.net/spch2008/article/details/11569127


示例代码:

from kombu.entity import Exchange, Queue
from kombu.messaging import Consumer
from kombu.connection import Connection

connection = Connection('amqp://guest:bupt@172.16.4.1:5672//')
channel = connection.channel()

news_exchange = Exchange('news', type='topic')
bound_exchange = news_exchange(channel)
bound_exchange.declare()
第9行声明一个Exchange,并不能再上面执行任何操作,只是描述了一下这个Exchange的特性。

第10行将exchange与特定的channel进行绑定。内部其实只是复制了自身,然后将_channel赋值而已。(Exchange内部记住了channel)

def __call__(self, channel):
    return self.bind(channel)

def bind(self, channel):
    return copy(self).maybe_bind(channel)

def maybe_bind(self, channel):
    if not self.is_bound and channel:
        self._channel = channel
        self.when_bound()
        self._is_bound = True
    return self

def when_bound(self):
    pass
第11行,在服务器上创建Exchange。这样,通过命令rabbitmqctl list_exchanges就可以看到创建的exchange。



参数说明:

class kombu.Exchange(name='', type='', channel=None, **kwargs)

	Parameters:	
	name -  Exchange名字
        type –  direct, fanout,topic,header几种类型
        channel – Exchange需要绑定的channel
        durable – server重启后是否恢复Exchange,默认True,即重启后Exchange仍然存在
        delivery_mode – transient模式,消息只存储于内存server重启或死机,消息丢失。
		                persistent模式,消息存在内存与硬盘,信息不丢失,默认persistent。


函数说明:

declare(self, nowait=False)   server上创建Exchange
    nowait True 不等待Server的响应信息。

delete(self, if_unused=False, nowait=False)  server上删除Exchange
    if_unused  True只在Exchange没有使用的时候删除



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值