package com.ruoyi.cai.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


@Configuration
public class RoomSettleDelayMqConfig {

    public static final String EXCHANGE_NAME = "roomSettleDelayExchange";
    public static final String QUEUE_NAME = "roomSettleDelayQueue";
    public static final String ROUTING_KEY = "roomSettleDelayRouting";

    @Bean
    public CustomExchange roomSettleDelayedExchange() {
        HashMap<String,Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(EXCHANGE_NAME,
                "x-delayed-message", // 消息类型
                true, // 是否持久化
                false,// 是否自动删除
                args);
    }

    @Bean
    public Queue roomSettleDelayedQueue() {
        return QueueBuilder.durable(QUEUE_NAME)
                .withArgument("x-delayed-type", "direct")
                .build();
    }

    @Bean
    public Binding roomSettleDelayedBinding(Queue roomSettleDelayedQueue,CustomExchange roomSettleDelayedExchange) {
        return BindingBuilder.bind(roomSettleDelayedQueue).to(roomSettleDelayedExchange).with(ROUTING_KEY).noargs();
    }

}
