RabbitMQ exchange使用-主题模式
1 简介
Topic exchange is powerful and can behave like other exchanges.
When a queue is bound with "#" (hash) binding key - it will receiveall the messages, regardless of the routing key - like in fanout exchange.
When special characters "*" (star) and "#" (hash) aren't used in bindings,the topic exchange will behave just like a direct one.
这个就没啥代码了,代码和路由模式的一模一样,
就是这个路由routingKey 支持匹配通配符模式
"*" 匹配一个
"#" 匹配多个
交换机类型 : topic
//声明一个交换机
channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
2.代码除了声明交换机类型不一样,其他和路由模式一样