package net.yyc.common.rabbitmq.exchange;

import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;

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

/**
 * 延迟交换器构造器
 */
public class DelayExchangeBuilder {
    /**
     * 默认延迟消息交换器
     */
    public final static  String DEFAULT_DELAY_EXCHANGE = "default.delayed.exchange";
    /**
     * 普通交换器
     */
    public final static  String DEFAULT_DIRECT_EXCHANGE = "default.direct.exchange";

    public final static  String DEFAULT_DLX_EXCHANGE = "default.dlx.exchange";

    /**
     * 构建延迟消息交换器
     * @return
     */
    public static CustomExchange buildExchange() {
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DEFAULT_DELAY_EXCHANGE, "x-delayed-message", true, false, args);
    }

    public static Exchange buildDirectExchange() {
        return ExchangeBuilder
                .directExchange(DEFAULT_DELAY_EXCHANGE)
                .delayed()
                .durable(true)
                .build();
    }


    public static Exchange buildDLXExchange() {
        return new DirectExchange(DEFAULT_DELAY_EXCHANGE, true, false);
        //return ExchangeBuilder
        //        .directExchange(DEFAULT_DELAY_EXCHANGE)
        //        .durable(true)
        //        .build();
    }
}
