1.服务器安装rabbitmq环境
2.springboot引入maven包
3.初始化队列bean,@Bean
4.发送:controller层调用Amqptemplate.convertAndSend(“队列名称”,”数据“)
topic模糊匹配到指定队列:
Amqptemplate.convertAndSend(“TopicExchange“,“队列名称匹配词”,“数据”)
Amqptemplate.convertAndSend(“FanoutExchange“,“数据”)
模糊分类模式:
BindingBuilder.bind(队列bean).to(TopicExchange).with(队列匹配词路由);
订阅模式:
BindingBuilder.bind(队列bean).to(FanoutExchange);
5.接收:@RabbitListener(对接队列)
@RabbitHandler(接收数据)
6.总结:
①数据直接发送到queue队列bean
②在数据和队列bean之间加一层缓冲exchange
7.总结:
①数据对接队列bean
②数据对接exchange,exchange对接队列bean
8.rabbitmq所有模式都是发布订阅,
direct,topic,fanout=多交换机多队列
direct=指定路由交换机
topic=模糊匹配分类路由交换机
fanout=无路由交换机
应用场景:
注册,秒杀,订单,日志,聊天室