TopicExchange 用消息的routingKey与Exchange和queue间binding-key进行模糊*或者#模式匹配
DirectExchange 用消息的routingKey与Exchange和queue间的binding-key进行完全匹配
CustomerExchange
FanoutExchange 订阅模式,与 routingKey和binding-key无关,将消息发给所有绑定关系的所有队列
- 生产者
rabbitTemplate.convertAndSend(exchange, routingKey,object)
rabbitTemplate.convertAndSend(
“scf.loan.warehouse.common.notice.exchange”,
“scf.loan.warehouse.common.notice.key”,
msgMap)
- 配置类
@Bean
Public Queue wrCommonNoticeQueue(){
Queue queue=new Queue(“scf.loan.warehouse.common.notice.queue”);
Return queue;
}
@Bean
Public TopicExchange wrCommonNoticeExchange(){
Return new TopicExchange(“scf.loan.warehouse.common.notice.exchange”)
}
Return BindingBuilder.bind(Queue).to(TopicExchange).with(routingKey)
@Bean
Public Binding wrCommonNoticeBingding(Queue wrCommonNoticeQueue, TopicExchange wrCommonNoticeExchange){
Return BindingBuilder.bind(wrCommonNoticeQueue).to(wrCommonNoticeExchange).with(scf.loan.warehouse.common.notice.key)
}
- 消费者(监听)
@RabbitListener(queues=”scf.loan.warehouse.common.notice.queue”)
Public void listener(Map<String, Object> msg){
String busTraNo=(String) msp.get(“busTraNo”);
Object sendBean=msg.get(“sendBean”);
...
}