springboot 整合RabbitMQ时,topic模式收不到信息

生产者生产消息
public void send1() {
String context = "hi, i am message 1";
System.out.println("Sender : " + context);
this.rabbitTemplate.convertAndSend("topic.message", context);
}

配置绑定
@Configuration
public class TopicRabbitConfig {
final static String message = "topic.message";

@Bean
public Queue queueMessage() {
return new Queue(TopicRabbitConfig.message);
}
@Bean
TopicExchange exchange() {
return new TopicExchange("topicExchange");
}
@Bean
Binding bindingExchangeMessage(Queue queueMessage, TopicExchange exchange) {
return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
}
@Bean
Binding bindingExchangeMessages(Queue queueMessages, TopicExchange exchange) {
return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
}
}
消费者
@Component
@RabbitListener(queues = "topic.message")
public class TopicReceiver {
@RabbitHandler
public void process(String message) {
System.out.println("Topic Receiver1 : " + message);
}
}
@Component
@RabbitListener(queues = "topic.messages")
public class TopicReceiver2 {
@RabbitHandler
public void process(String message) {
System.out.println("Topic Receiver2 : " + message);
}
}
请教几个问题:
1、怎么只有TopicReceiver接收到信息
2、@RabbitListener(queues = "topic.message")中的topic.message必须跟生产者的一样,不然就收不到信息。
3、我把TopicRabbitConfig 删除程序一样有效,而且消费者能收到信息,效果跟有TopicRabbitConfig 是一样的

没明白你的意思,里面没有RabbitMQ的东西呀

这个问题是怎么解决的?我也遇到同样的问题

挖个坟,相信楼主应该已经早就明白了其中的原理,但是防止后续读者看到仍然不明白,简单回答一下:
其实三个问题的答案都是同一个,就是楼主在发送队列消息的时候使用错了方法:
this.rabbitTemplate.convertAndSend("topic.message", context);//缺省路由的方法,默认使用direct模式,即全匹配才可以接收到消息。
所以三个问题会是上面的现象。
将接口改成
this.rabbitTemplate.convertAndSend("topicExchange","topic.message", context);就可以了。其中"topicExchange"是楼主自定义的路由信息。

http://blog.csdn.net/u012734441/article/details/51542747