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;

@Configuration
public class DrawGoodConfig {

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

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

	    @Bean
	    public Queue drawGoodQueue() {
	        return new Queue(QueueTypeEnum.DRAW_GOODS_APPLY.getQueue());
	    }

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

	    @Bean
	    Binding drawGoodBinding(DirectExchange drawGoodDirect, Queue drawGoodQueue) {
	        return BindingBuilder.bind(drawGoodQueue).to(drawGoodDirect).with(QueueTypeEnum.DRAW_GOODS_APPLY.getQueueKey());
	    }

	    @Bean
	    public Binding drawGoodTTLBinding(Queue drawGoodTTLQueue, DirectExchange drawGoodTTLDirect) {
	        return BindingBuilder.bind(drawGoodTTLQueue).to(drawGoodTTLDirect)
	                .with(QueueTTLTypeEnum.DRAW_GOODS_APPLY_TTL.getQueueKey());
	    }
	    
}
