我尝试按如下方式发送消息:
rabbitTemplate.convertAndSend("my.exchange", "my.queue", "Test Message");
并尝试接收如下消息:
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "my.queue", durable = "true"), exchange = @Exchange(value = "my.exchange", durable = "true", type = ExchangeTypes.TOPIC)))
public void receiveAuditMessage(String message) {
log.info("Received <" + message + ">");
}
没用。
但是如果我在@SpringBootApplication中指定了Queue,TopicExchange,Binding,那么它的工作正常。
@Bean
Queue queue() {
return new Queue("my.queue");
}
@Bean
TopicExchange exchange() {
return new TopicExchange("my.exchange");
}
@Bean
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with("my.queue");
}
是否必须在SpringBootApplication中指定Queue,TopicExchange,Binding? 如果是,那么如何在SpringBootApplication中指定多个Queue,TopicExchange,Binding?
请在这里帮助我。感谢。
答案 0 :(得分:0)
在第一种情况下,您正在创建队列和交换,但没有绑定的路由键;你需要一个TOPIC交换的路由密钥......
if (!preg_match('/[^A-Za-z0-9]+/', $string)) {
// $string contains only English letters and digits
}
或@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "my.queue", durable = "true"),
exchange = @Exchange(value = "my.exchange", durable = "true", type = ExchangeTypes.TOPIC),
key = "my.queue"))
public void receiveAuditMessage(String message) {
System.out.println("Received <" + message + ">");
}
获取所有讯息。