延迟消息

@Configuration
public class DelayConfig {

    public static final String DELAYED_QUEUE_NAME = "delay.queue.xxx.queue";
    public static final String DELAYED_EXCHANGE_NAME = "delay.queue.xxx.exchange";
    public static final String DELAYED_ROUTING_KEY = "delay.queue.xxx.evaluation";

    @Bean
    public Queue immediateQueue() {
        return new Queue(DELAYED_QUEUE_NAME);
    }

    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>(16);
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAYED_EXCHANGE_NAME, "x-delayed-message", true, false, args);
    }

    @Bean
    public Binding bindingNotify(@Qualifier("immediateQueue") Queue queue,
                                 @Qualifier("customExchange") CustomExchange customExchange) {
        return BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
    }
}
作者:Jeebiz  创建时间:2023-03-30 12:02
最后编辑:Jeebiz  更新时间:2024-11-01 10:06