package com.fzm.mall.server.front.mq.config;

import com.fzm.mall.server.front.enums.QueueTTLTypeEnum;
import com.fzm.mall.server.front.enums.QueueTypeEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
  * 提币rabbitmq消息配置
 * @author lgang
 * @date 创建时间：2018年12月17日 下午4:47:20
 *
 */
@Configuration
public class WithdrawConfig {

    @Bean
    DirectExchange withdrawDirect() {
        return (DirectExchange) ExchangeBuilder.directExchange(QueueTypeEnum.CONFIRM_WITHDRAW.getExchange())
                .durable(true).build();
    }

    @Bean
    DirectExchange withdrawTTLDirect() {
        return (DirectExchange) ExchangeBuilder.directExchange(QueueTTLTypeEnum.CONFIRM_WITHDRAW_TTL.getExchange())
                .durable(true).build();
    }

    @Bean
    public Queue withdrawQueue() {
        return new Queue(QueueTypeEnum.CONFIRM_WITHDRAW.getQueue());
    }

    @Bean
    public Queue withdrawTTLQueue() {
        return QueueBuilder.durable(QueueTTLTypeEnum.CONFIRM_WITHDRAW_TTL.getQueue())
                // 配置到期后转发的交换
                .withArgument("x-dead-letter-exchange", QueueTypeEnum.CONFIRM_WITHDRAW.getExchange())
                // 配置到期后转发的路由键
                .withArgument("x-dead-letter-routing-key", QueueTypeEnum.CONFIRM_WITHDRAW.getQueueKey()).build();
    }

    @Bean
    Binding withdrawBinding(DirectExchange withdrawDirect, Queue withdrawQueue) {
        return BindingBuilder.bind(withdrawQueue).to(withdrawDirect).with(QueueTypeEnum.CONFIRM_WITHDRAW.getQueueKey());
    }

    @Bean
    public Binding withdrawTTLBinding(Queue withdrawTTLQueue, DirectExchange withdrawTTLDirect) {
        return BindingBuilder.bind(withdrawTTLQueue).to(withdrawTTLDirect)
                .with(QueueTTLTypeEnum.CONFIRM_WITHDRAW_TTL.getQueueKey());
    }


}
