修改autodelete ,交换器有此属性,消息队列也有,设为true表示临时,不会持久化,设为false,服务器宕机也能保存到磁盘

 
  1. @Component

  2. @RabbitListener(

  3. bindings = @QueueBinding(

  4. value = @Queue(value = "${mq.config.queue.sms}",autoDelete = "false"),

  5. exchange = @Exchange(value = "${mq.config.exchange}",type = ExchangeTypes.FANOUT)

  6. )

  7. )

  8. public class Accepter {

  9. /**接收消息的方法

  10. * 注解的监听队列名称,可以是数组

  11. */

  12. /* @RabbitListener(queues={"hello-queue"})

  13. public void process(String msg){

  14. System.out.println("这是接收到的消:{}"+msg);

  15. }*/

  16.  
  17. @RabbitHandler

  18. public void process(String msg){

  19. System.out.println("这是接收到的消息sms:{}"+msg);

  20. }

  21. }