package com.education.business.message.queue;

import com.education.business.message.config.MqSocketConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zjt
 * @version 2.14.0
 * @Description
 * @createTime 2025/2/25 10:51
 */
@Configuration
public class SocketQueueConfig {

    @Resource
    private MqSocketConfig mqSocketConfig;

    /**
     * 创建socket通讯消息队列
     * @return
     */
    @Bean
    public Queue socketQueue() {
        return new Queue(mqSocketConfig.getQueue());
    }

    /**
     * 交换机配置
     * @return
     */
    @Bean
    public FanoutExchange socketDirectExchange() {
        return ExchangeBuilder
                .fanoutExchange(mqSocketConfig.getDirectExchange())
                .build();
    }

    @Bean
    public Binding bindingSocketExchange(FanoutExchange socketDirectExchange, Queue socketQueue) {
        return BindingBuilder.bind(socketQueue).to(socketDirectExchange);
    }
}
