package com.backendsys.modules.common.config.rabbitmq.queue;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 死信队列
 * 在项目启动时创建 (RabbitMQ) 队列、交换机、绑定关系
 */
@Configuration
@Lazy(false)
public class DemoDlxQueueConfig {

    /* === 死信交换机/队列 === */
    public static final String EXCHANGE = "demo.dlx";
    public static final String QUEUE = "demo.dlx.queue";
    public static final String ROUTING_KEY = "demo.dlx.routekey";

    @Bean
    public DirectExchange demoDlxExchange() { return ExchangeBuilder.directExchange(EXCHANGE).durable(true).build(); }

    @Bean
    public Queue demoDlxQueue() { return QueueBuilder.durable(QUEUE).build(); }

    @Bean
    public Binding demoDlxBinding() { return BindingBuilder.bind(demoDlxQueue()).to(demoDlxExchange()).with(ROUTING_KEY); }

}
