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 UserAssetTransferConfig {

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

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

    @Bean
    public Queue userAssetTransferQueue() {
        return new Queue(QueueTypeEnum.MALL_USER_ASSET_TRANSFER.getQueue());
    }

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

    @Bean
    Binding userAssetTransferBinding(DirectExchange userAssetTransfer, Queue userAssetTransferQueue) {
        return BindingBuilder.bind(userAssetTransferQueue).to(userAssetTransfer).with(QueueTypeEnum.MALL_USER_ASSET_TRANSFER.getQueueKey());
    }

    @Bean
    public Binding userAssetTransferTTLBinding(Queue userAssetTransferTTLQueue, DirectExchange userAssetTransferTTL) {
        return BindingBuilder.bind(userAssetTransferTTLQueue).to(userAssetTransferTTL)
                .with(QueueTTLTypeEnum.MALL_USER_ASSET_TRANSFER_TTL.getQueueKey());
    }


}
