package com.yeshi.fanli.util.mq.rabbit;
|
|
import org.springframework.amqp.core.Binding;
|
import org.springframework.amqp.core.BindingBuilder;
|
import org.springframework.amqp.core.CustomExchange;
|
import org.springframework.amqp.core.Queue;
|
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @author hxh
|
* @title: RabbitmqConfig
|
* @description: TODO
|
* @date 2024/10/12 11:10
|
*/
|
@Configuration
|
@EnableRabbit
|
public class RabbitmqConfig {
|
@Bean("pluginDelayExchange")
|
public CustomExchange pluginDelayExchange() {
|
Map<String, Object> argMap = new HashMap<>();
|
argMap.put("x-delayed-type", "direct");//必须要配置这个类型,可以是direct,topic和fanout
|
//第二个参数必须为x-delayed-message
|
return new CustomExchange(RabbitmqSenderUtil.DELAY_EXCHANGE_NAME, "x-delayed-message", false, false, argMap);
|
}
|
|
|
@Bean("pluginDelayQueue")
|
public Queue pluginDelayQueue() {
|
Map<String, Object> headers=new HashMap<>();
|
headers.put("x-message-ttl", 24*60*60*1000);
|
return new Queue(RabbitmqSenderUtil.DELAY_QUEUE_NAME,true, false, false, headers);
|
}
|
|
@Bean("pluginDelayConsumeFailQueue")
|
public Queue pluginDelayConsumeFailQueue() {
|
Map<String, Object> headers=new HashMap<>();
|
headers.put("x-message-ttl", 24*60*60*1000);
|
return new Queue(RabbitmqSenderUtil.CONSUME_FAIL_QUEUE_NAME,true, false, false, headers);
|
}
|
|
@Bean
|
public Binding pluginDelayBinding(@Qualifier("pluginDelayQueue") Queue queue, @Qualifier("pluginDelayExchange") CustomExchange customExchange) {
|
return BindingBuilder.bind(queue).to(customExchange).with(RabbitmqSenderUtil.ROUTING_KEY_COMMON_DELAY).noargs();
|
}
|
|
@Bean
|
public Binding pluginDelayConsumeFailBinding(@Qualifier("pluginDelayConsumeFailQueue") Queue queue, @Qualifier("pluginDelayExchange") CustomExchange customExchange) {
|
return BindingBuilder.bind(queue).to(customExchange).with(RabbitmqSenderUtil.ROUTING_KEY_CONSUME_FAIL_DELAY).noargs();
|
}
|
|
|
}
|