package com.lovecoding.rabbitmq.consumer;


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;

@Configuration
public class DeadConfig {

    @Bean
    public DirectExchange deadDirectExchange(){
        return new DirectExchange("deadDirectExchange");
    }

    @Bean
    public Queue deadQueue(){
        return new Queue("deadQueue");
    }

    @Bean
    public DirectExchange deadDirectExchangeDemo(){
        return new DirectExchange("deadDirectExchangeDemo");
    }

    @Bean
    public Queue deadQueueDemo(){
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", "deadDirectExchange" );
        args.put("x-dead-letter-routing-key", "dead" );
        //args.put("x-max-length", 6);
        args.put("x-message-ttl", 10000);
        return new Queue("deadQueueDemo",
                false, false, false, args);
    }

    @Bean
    public Binding deadQueueDemoBinding(Queue deadQueueDemo, DirectExchange deadDirectExchangeDemo){
        return BindingBuilder.bind(deadQueueDemo).to(deadDirectExchangeDemo).with("tianqi");
    }

    @Bean
    public Binding deadQueueBinding(Queue deadQueue, DirectExchange deadDirectExchange){
        return BindingBuilder.bind(deadQueue).to(deadDirectExchange).with("dead");
    }
}
