package com.backendsys.modules.sdk.comfyui.rabbitmq;

import com.backendsys.modules.common.config.rabbitmq.queue.DemoDlxQueueConfig;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * 非懒加载，在项目启动时创建 RabbitMQ 队列、交换机、绑定关系
 */
@Configuration
@Lazy(false)
public class ComfyuiQueueConfig {

    @Autowired
    private ComfyuiQueueDlxConfig config;

    public static final String EXCHANGE = "comfyui.exchange";
    public static final String QUEUE = "comfyui.queue";
    public static final String ROUTING_KEY = "comfyui.create";

    // 交换机
    @Bean
    public DirectExchange comfyuiExchange() {
        return ExchangeBuilder.directExchange(EXCHANGE).durable(true).build();
    }

    // 队列
    @Bean
    public Queue comfyuiQueue() {
        return QueueBuilder.durable(QUEUE)
            .deadLetterExchange(config.EXCHANGE)
            .deadLetterRoutingKey(config.ROUTING_KEY)
            .build();
    }

    // 队列绑定交换机
    @Bean
    public Binding comfyuiBinding() {
        return BindingBuilder.bind(comfyuiQueue()).to(comfyuiExchange()).with(ROUTING_KEY);
    }


}
