- 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()); } }