rabbitmq 学习 之exchange to exchange bindings(36)

Overview

In AMQP 0-9-1 the queue.bind method binds a queue to an exchange so that messages flow (subject to various criteria) from the exchange (the source) to the queue (the destination). We have introduced an exchange.bind method which binds one exchange to another exchange. The binding is semantically identical to exchange-to-queue bindings: unidirectional, binding keys and exchange types operate as normal, but both endpoints (the source and destination) of the binding are exchanges. This allows far richer routing topologies to be created. Note the source and destination fields in the exchange.bind method reflect the flow of messages: from the exchange at the source, and to the exchange at the destination.

Just like with queue.bind, multiple distinct bindings can be created between the same binding-endpoints. We detect and eliminate cycles during message delivery, and ensure that transitively, over any routing topology, for every queue to which a given message is routed, each queue will receive exactly one copy of that message. Exchanges which are declared as auto-delete will still be removed when all their bindings are removed, regardless of whether those bindings are to queues or exchanges. Note that an auto-delete exchange will only be deleted when bindings for which the exchange is the source are removed: if you add exchange-to-exchange bindings for which the given exchange is the destination then that exchange will not be auto-deleted on removal of those bindings.

Java Client Example

Use the Channel#exchangeBind method. The following example binds an exchange "destination" to "source" with routing key "routingKey".

Channel ch = conn.createChannel();
ch.exchangeBind("destination", "source", "routingKey");

//待测试  发送一个消息 到 source ,routingkey 看消息是否会到达 destination routingkey 绑定的队列。

用于场景  2套程序用2个exchange ,谁都不想改,有可能交换机类型不同或者 各自的交换机下 绑定了好多队列,

这个时候发送方 发送消息到 自己的交换机所在的队列,然后同时利用exchage to exchange 功能就把消息发送到了 另外一个exchange的队列,大家都不用改东西。否则,其中一方就得修改自己代码,去连接别人的交换机。 

.NET Client Example

Use the IModel#ExchangeBind method. The following example binds an exchange "destination" to "source" with routing key "routingKey".

var ch = conn.CreateModel();
ch.ExchangeBind("destination", "source", "routingKey");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值