Fanout、Direct、Topic 三种 Exchange Type 的区别
* (star) can substitute for exactly one word # (hash) can substitute for zero or more words
headers 以后再探讨
系统中默认就有如下 exchange
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
| name | type |
+--------------------+---------+
| | direct |
| amq.direct | direct |
| amq.fanout | fanout |
| amq.headers | headers |
| amq.match | headers |
| amq.rabbitmq.log | topic |
| amq.rabbitmq.trace | topic |
| amq.topic | topic |
+--------------------+---------+
[root@h102 rabbitmq]#
我们创建了一个 queue 后,系统自动为它定义了一个 binding
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
| | test | test |
+--------+-------------+-------------+
[root@h102 rabbitmq]#
从中我们看出了一些端倪,我们不手动指定 exchange时,使用的默认 exchange是空字符串(系统中的第一个exchange,binding中的source部分),并且这个默认的exchange是 direct 类型,这种隐式调用确保了我的消息准确投递
这里再定义三个exchange 分属三种类型
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
| name | type |
+--------------------+---------+
| | direct |
| amq.direct | direct |
| amq.fanout | fanout |
| amq.headers | headers |
| amq.match | headers |
| amq.rabbitmq.log | topic |
| amq.rabbitmq.trace | topic |
| amq.topic | topic |
+--------------------+---------+
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.fanout type=fanout
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.direct type=direct
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin declare exchange name=my.topic type=topic
exchange declared
[root@h102 rabbitmq]# rabbitmqadmin list exchanges
+--------------------+---------+
| name | type |
+--------------------+---------+
| | direct |
| amq.direct | direct |
| amq.fanout | fanout |
| amq.headers | headers |
| amq.match | headers |
| amq.rabbitmq.log | topic |
| amq.rabbitmq.trace | topic |
| amq.topic | topic |
| my.direct | direct |
| my.fanout | fanout |
| my.topic | topic |
+--------------------+---------+
[root@h102 rabbitmq]#
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+--------+-------------+-------------+
| source | destination | routing_key |
+--------+-------------+-------------+
| | test | test |
+--------+-------------+-------------+
[root@h102 rabbitmq]#
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。