package cn.edu.zjvtit.cloudstorage.dataservice.rabbitmq.topic;

import org.slf4j.Logger;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
@RabbitListener(queues = "dataServers")
public class Receiver {
    @Autowired//自动装配
    Logger logger;//日志
    @Autowired//自动装配
    Sender sender;//发送者
    @Autowired//自动装配
    private RabbitTemplate rabbitTemplate;//定义私有的消息模板

    @RabbitHandler//方法处理
    public void process(String filename) {
        File file = new File("./uploads/" + filename);//分配空间路径为upload文件夹下
        if(!file.exists()){//判断文件是否存在
            return;
        }
        logger.info("Receiver: " + filename);//日志信息为接收者的文件名
        sender.sendFileInfo(filename);//发送文件名为的信息

    }
}
