- AmqpAdmin:RabbitMQ系統管理功能組件(可以創建exchange,queue,Binding)
@Test public void createExchange(){ //創建交換器 //amqpAdmin.declareExchange(new DirectExchange("amqpadmin.exchange")); //創建隊列(如果存在同名,則不創建) amqpAdmin.declareQueue(new Queue("amqpadmin.queue",true)); //創建綁定規則 new Binding(目的地,目的地類型,交換器名字,路由件,參數頭) //amqpAdmin.declareBinding(new Binding("amqpadmin.queue", Binding.DestinationType.QUEUE,"amqpadmin.exchange","amqp.haha",null)); //刪除隊列 //amqpAdmin.deleteQueue("amqpadmin.queue"); }


- @EnableRabbit+@RabbitListener 監聽消息隊列的內容
@Service public class BookService { @RabbitListener(queues = "springbootTest") public void receive(Book book){ System.out.println("收到的消息為:"+book.toString()); } @RabbitListener(queues = "springbootTest") public void receive02(Message msg){ //字節內容對象 System.out.println(msg.getBody()); //頭對象 System.out.println(msg.getMessageProperties()); } }