parent
a5cd1d7fe1
commit
9bbeb47e53
@ -0,0 +1,21 @@
|
|||||||
|
package com.xjs.business.api;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.api.factory.RemoteWeatherFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rpc远程调用其他服务天气接口
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-16
|
||||||
|
*/
|
||||||
|
@FeignClient(contextId = "remoteTWeatherFeign",
|
||||||
|
value = ServiceNameConstants.BUSINESS_OPENAPI_SERVICE,
|
||||||
|
fallbackFactory = RemoteWeatherFactory.class)
|
||||||
|
public interface RemoteWeatherFeign {
|
||||||
|
|
||||||
|
@GetMapping("/weather/getWeatherForRPC")
|
||||||
|
R getWeatherForRPC() ;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.xjs.business.api.factory;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.api.RemoteWeatherFeign;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部调用天气服务降级
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-16
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RemoteWeatherFactory implements FallbackFactory<RemoteWeatherFeign> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteWeatherFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteWeatherFeign create(Throwable cause) {
|
||||||
|
log.error("api模块天气服务调用失败:{}", cause.getMessage());
|
||||||
|
return () -> R.fail("天气服务调用失败" + cause.getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.xjs.job.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.xjs.business.api.RemoteWeatherFeign;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用天气定时任务
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-16
|
||||||
|
*/
|
||||||
|
@Component("WeatherTask")
|
||||||
|
public class WeatherTask {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteWeatherFeign remoteWeatherFeign;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WeatherTask.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务执行
|
||||||
|
*/
|
||||||
|
public void execute() {
|
||||||
|
LocalDateTime localDateTime1 = DateUtil.date().toLocalDateTime();
|
||||||
|
log.info("---------------天气定时任务Start-------------------");
|
||||||
|
R r = remoteWeatherFeign.getWeatherForRPC();
|
||||||
|
log.info("天气定时任务结果:code={},msg={},data={}",r.getCode(),r.getMsg(),r.getData());
|
||||||
|
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||||
|
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||||
|
log.info("Job耗费时间:{}ms", between);
|
||||||
|
log.info("---------------天气定时任务end---------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue