6 changed files with 135 additions and 3 deletions
@ -0,0 +1,42 @@ |
|||||
|
package com.elink.esua.epdc.config; |
||||
|
|
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.core.task.TaskExecutor; |
||||
|
import org.springframework.scheduling.annotation.EnableAsync; |
||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
||||
|
|
||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||
|
|
||||
|
/** |
||||
|
* 线程池 |
||||
|
* |
||||
|
* @author rongchao |
||||
|
* @Date 18-11-27 |
||||
|
*/ |
||||
|
@Configuration |
||||
|
@EnableAsync |
||||
|
public class ThreadConfig { |
||||
|
|
||||
|
@Bean |
||||
|
public TaskExecutor taskExecutor() { |
||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
||||
|
// 设置核心线程数
|
||||
|
executor.setCorePoolSize(5); |
||||
|
// 设置最大线程数
|
||||
|
executor.setMaxPoolSize(10); |
||||
|
// 设置队列容量
|
||||
|
executor.setQueueCapacity(20); |
||||
|
// 设置线程活跃时间(秒)
|
||||
|
executor.setKeepAliveSeconds(60); |
||||
|
// 设置默认线程名称
|
||||
|
executor.setThreadNamePrefix("esd-"); |
||||
|
// 设置拒绝策略
|
||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
||||
|
// 等待所有任务结束后再关闭线程池
|
||||
|
executor.setWaitForTasksToCompleteOnShutdown(true); |
||||
|
executor.setAwaitTerminationSeconds(60); |
||||
|
executor.initialize(); |
||||
|
return executor; |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
package com.elink.esua.epdc.modules.async; |
||||
|
|
||||
|
import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; |
||||
|
import com.elink.esua.epdc.modules.feign.NewsFeignClient; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.scheduling.annotation.Async; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* 新闻通知消息模块 线程任务 |
||||
|
* |
||||
|
* @author work@yujt.net.cn |
||||
|
* @date 2019/9/18 15:39 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class NewsTask { |
||||
|
|
||||
|
@Autowired |
||||
|
private NewsFeignClient newsFeignClient; |
||||
|
|
||||
|
/** |
||||
|
* 给用户发送消息 |
||||
|
* |
||||
|
* @param informationDto |
||||
|
* @return void |
||||
|
* @author work@yujt.net.cn |
||||
|
* @date 2019/9/18 15:39 |
||||
|
*/ |
||||
|
@Async |
||||
|
public void insertUserInformation(EpdcInformationFormDTO informationDto) { |
||||
|
newsFeignClient.saveInformation(informationDto); |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.elink.esua.epdc.modules.feign; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
||||
|
import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; |
||||
|
import com.elink.esua.epdc.modules.feign.fallback.NewsFeignClientFallback; |
||||
|
import org.springframework.cloud.openfeign.FeignClient; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
|
||||
|
/** |
||||
|
* 消息模块 |
||||
|
* |
||||
|
* @author work@yujt.net.cn |
||||
|
* @date 2019/9/18 15:37 |
||||
|
*/ |
||||
|
@FeignClient(name = ServiceConstant.EPDC_NEWS_SERVER, fallback = NewsFeignClientFallback.class) |
||||
|
public interface NewsFeignClient { |
||||
|
|
||||
|
/** |
||||
|
* 给用户发消息 |
||||
|
* |
||||
|
* @param formDto |
||||
|
* @return com.elink.esua.epdc.commons.tools.utils.Result |
||||
|
* @author work@yujt.net.cn |
||||
|
* @date 2019/9/18 15:40 |
||||
|
*/ |
||||
|
@PostMapping(value = "news/epdc-app/information/save", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) |
||||
|
Result saveInformation(@RequestBody EpdcInformationFormDTO formDto); |
||||
|
|
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package com.elink.esua.epdc.modules.feign.fallback; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
||||
|
import com.elink.esua.epdc.dto.epdc.form.EpdcInformationFormDTO; |
||||
|
import com.elink.esua.epdc.modules.feign.NewsFeignClient; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @author work@yujt.net.cn |
||||
|
* @date 2019/9/18 15:38 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class NewsFeignClientFallback implements NewsFeignClient { |
||||
|
|
||||
|
@Override |
||||
|
public Result saveInformation(EpdcInformationFormDTO formDto) { |
||||
|
return ModuleUtils.feignConError(ServiceConstant.EPDC_NEWS_SERVER, "saveInformation", formDto); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue