package cn.edu.zjvtit.cloudstorage.dataservice.schedule;

import cn.edu.zjvtit.cloudstorage.dataservice.rabbitmq.topic.Sender;
import com.rabbitmq.client.impl.Environment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.time.LocalDateTime;

@Component
public class ScheduledTask {
    @Autowired//自动装配
    Sender sender;//定义Sender属性字段sender

    private String getAddress(){
        try {
            return InetAddress.getLocalHost().getHostAddress();//返回通过本机名获得的本机ip
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
    @Scheduled(fixedRate = 3000)//开启定时计划，间隔3秒
    public void scheduledTask() {
        sender.sendServerAddress();
    }
    //心跳上报
}

