可以成功发布,然后我尝试了不指定 exchange,只指定 routing_key=first ,发现报 Message published but NOT routed ,说明不指定 exchange 的情况下,系统又默认去找为空的 exchange,并且在它下面去找 routing_key=first 的binding ,但是没找到,于是信息路由不成功
定义第二个queue ,也使用 my.fanout binding 起来,取 routing_key 为 second
[root@h102 rabbitmq]# rabbitmqadmin list queues
+------+----------+
| name | messages |
+------+----------+
| test | 1 |
+------+----------+
[root@h102 rabbitmq]# rabbitmqadmin declare queue name=test.fanout durable=true
queue declared
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
| name | messages |
+-------------+----------+
| test | 1 |
| test.fanout | 0 |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
| source | destination | routing_key |
+-----------+-------------+-------------+
| | test | test |
| | test.fanout | test.fanout |
| my.fanout | test | first |
+-----------+-------------+-------------+
[root@h102 rabbitmq]#
[root@h102 rabbitmq]# rabbitmqadmin declare binding source=my.fanout destination=test.fanout routing_key=second
binding declared
[root@h102 rabbitmq]# rabbitmqadmin list bindings
+-----------+-------------+-------------+
| source | destination | routing_key |
+-----------+-------------+-------------+
| | test | test |
| | test.fanout | test.fanout |
| my.fanout | test | first |
| my.fanout | test.fanout | second |
+-----------+-------------+-------------+
[root@h102 rabbitmq]#
尝试再发一条数据到 my.fanout 中
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
| name | messages |
+-------------+----------+
| test | 1 |
| test.fanout | 0 |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin publish routing_key=second exchange=my.fanout payload="just for test3"
Message published
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
| name | messages |
+-------------+----------+
| test | 2 |
| test.fanout | 1 |
+-------------+----------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count | payload | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| first | my.fanout | 1 | just for test1 | 14 | string | | True |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin get queue=test.fanout requeue=true
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count | payload | payload_bytes | payload_encoding | properties | redelivered |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
| second | my.fanout | 0 | just for test3 | 14 | string | | False |
+-------------+-----------+---------------+----------------+---------------+------------------+------------+-------------+
[root@h102 rabbitmq]# rabbitmqadmin list queues
+-------------+----------+
| name | messages |
+-------------+----------+
| test | 2 |
| test.fanout | 1 |
+-------------+----------+
[root@h102 rabbitmq]#
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。