Rabbitmq 消息队列类型
- Direct Exchange(直连交换机)
- Fanout Exchange(扇型交换机)
- Topic Exchange(主题交换机)
- Headers Exchange(头交换机)
配置队列
@Bean
public Queue orderGeneratedQueue() {
Map<String, Object> arguments = new HashMap<>();
arguments.put("x-dead-letter-exchange", ORDER_GENERATED_EXCHANGE_DLQ);
arguments.put("x-message-ttl", TIME_TO_LIVE);
return new Queue(ORDER_GENERATED_QUEUE, true, false, false, arguments);
}
配置交换机
@Bean
public FanoutExchange orderGeneratedExchange() {
return new FanoutExchange(ORDER_GENERATED_EXCHANGE, true, false);
}
配置绑定关系
@Bean
public Binding bindingDlq() {
return BindingBuilder.bind(orderGeneratedQueueDlq()).to(orderGeneratedExchangeDlq());
}
接收消息
@RabbitListener(queues = OrderGeneratedMount.ORDER_GENERATED_QUEUE_DLQ)
public void listenDlq(OrderGeneratedPayload payload) {
System.out.println("aaa");
}
发送消息
public void publisher(OrderGeneratedPayload payload) {
rabbitTemplate.convertAndSend(OrderGeneratedMount.ORDER_GENERATED_EXCHANGE, OrderGeneratedMount.ORDER_GENERATED_EXCHANGE,payload);
}