package com.mortals.xhx.base.framework.config;

import com.mortals.xhx.common.key.QueueKey;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig {
    public Integer messageTtl = 86400000;
    public Map<String, Object> args = new HashMap<>();

    // 创建 Queue
    @Bean
    public Queue alarmMsgQueue() {
        args.put("x-message-ttl", messageTtl);
        return new Queue(QueueKey.ALARM_MSG_QUEUE, // Queue 名字
                true, // durable: 是否持久化
                false, // exclusive: 是否排它
                false,
                args); // autoDelete: 是否自动删除
    }

    // 创建 Direct Exchange
    @Bean
    public DirectExchange exchange() {
        return new DirectExchange(QueueKey.EXCHANGE,
                true,  // durable: 是否持久化
                false);  // exclusive: 是否排它
    }

    // 创建 Binding
    @Bean
    public Binding accessBinding() {
        return BindingBuilder.bind(alarmMsgQueue()).to(exchange()).with(QueueKey.ALARM_MSG_QUEUE);
    }


}
