后台目录结构大调整,让结构更清晰

This commit is contained in:
zhangdaiscott
2022-08-12 14:14:11 +08:00
parent 5f88b0e216
commit 4b19f25111
1486 changed files with 94 additions and 213 deletions

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jeecg-cloud-test</artifactId>
<groupId>org.jeecgframework.boot</groupId>
<version>3.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<description>公共测试模块</description>
<artifactId>jeecg-cloud-test-more</artifactId>
<dependencies>
<!-- 引入jeecg-boot-starter-cloud依赖 -->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-starter-cloud</artifactId>
<!--system模块需要排除jeecg-system-cloud-api-->
<exclusions>
<exclusion>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-cloud-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--定时任务-->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-starter-job</artifactId>
</dependency>
<!--rabbitmq消息队列-->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-starter-rabbitmq</artifactId>
</dependency>
<!-- 分布式锁依赖 -->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-starter-lock</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,26 @@
package org.jeecg.modules.test.constant;
/**
* 微服务单元测试常量定义
* @author: zyf
* @date: 2022/04/21
*/
public interface CloudConstant {
/**
* MQ测试队列名字
*/
public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order";
/**
* MQ测试消息总线
*/
public final static String MQ_DEMO_BUS_EVENT = "demoBusEvent";
/**
* 分布式锁lock key
*/
public final static String REDISSON_DEMO_LOCK_KEY1 = "demoLockKey1";
public final static String REDISSON_DEMO_LOCK_KEY2 = "demoLockKey2";
}

View File

@ -0,0 +1,30 @@
package org.jeecg.modules.test.feign.client;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.ServiceNameConstants;
import org.jeecg.config.FeignConfig;
import org.jeecg.modules.test.constant.CloudConstant;
import org.jeecg.modules.test.feign.factory.JeecgTestClientFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 常规feign接口定义
* @author: zyf
* @date: 2022/04/21
*/
@FeignClient(value = ServiceNameConstants.SERVICE_DEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class)
@Component
public interface JeecgTestClient {
/**
* feign测试方法
* @param name
* @return
*/
@GetMapping(value = "/test/getMessage")
String getMessage(@RequestParam(value = "name",required = false) String name);
}

View File

@ -0,0 +1,15 @@
//package org.jeecg.modules.test.feign.client;
//
//import org.jeecg.common.api.vo.Result;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//
///**
// * 动态feign接口定义
// */
//public interface JeecgTestClientDyn {
//
// @GetMapping(value = "/test/getMessage")
// Result<String> getMessage(@RequestParam(value = "name",required = false) String name);
//}

View File

@ -0,0 +1,78 @@
package org.jeecg.modules.test.feign.controller;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.test.feign.client.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* 微服务单元测试
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@RestController
@RequestMapping("/sys/test")
@Api(tags = "【微服务】单元测试")
public class JeecgTestFeignController {
@Autowired
private JeecgTestClient jeecgTestClient;
/**
* 熔断: fallbackFactory优先于 @SentinelResource
*
* @param name
* @return
*/
@GetMapping("/getMessage")
@ApiOperation(value = "测试feign调用demo服务1", notes = "测试feign @SentinelResource熔断写法 | 测试熔断关闭jeecg-demo服务")
@SentinelResource(value = "test_more_getMessage", fallback = "getDefaultUser")
public Result<String> getMessage(@RequestParam(value = "name", required = false) String name) {
log.info("---------Feign fallbackFactory优先级高于@SentinelResource-----------------");
String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!");
return Result.OK(null, resultMsg);
}
/**
* 测试方法关闭demo服务访问请求 http://127.0.0.1:9999/sys/test/getMessage
*
* @param name
* @return
*/
@GetMapping("/getMessage2")
@ApiOperation(value = "测试feign调用demo服务2", notes = "测试feign fallbackFactory熔断写法 | 测试熔断关闭jeecg-demo服务")
public Result<String> getMessage2(@RequestParam(value = "name", required = false) String name) {
log.info("---------测试 Feign fallbackFactory-----------------");
String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!");
return Result.OK(null, resultMsg);
}
@GetMapping("/fallback")
@ApiOperation(value = "测试熔断", notes = "测试熔断")
@SentinelResource(value = "test_more_fallback", fallback = "getDefaultUser")
public Result<Object> test(@RequestParam(value = "name", required = false) String name) {
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("name param is empty");
}
return Result.OK();
}
/**
* 熔断,默认回调函数
*
* @param name
* @return
*/
public Result<Object> getDefaultUser(String name) {
log.info("熔断,默认回调函数");
return Result.error(null, "访问超时, 自定义 @SentinelResource Fallback");
}
}

View File

@ -0,0 +1,23 @@
package org.jeecg.modules.test.feign.factory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.jeecg.modules.test.feign.client.JeecgTestClient;
import org.jeecg.modules.test.feign.fallback.JeecgTestFallback;
import org.springframework.stereotype.Component;
/**
* @author qinfeng
*/
@Component
public class JeecgTestClientFactory implements FallbackFactory<JeecgTestClient> {
@Override
public JeecgTestClient create(Throwable throwable) {
JeecgTestFallback fallback = new JeecgTestFallback();
fallback.setCause(throwable);
return fallback;
}
}

View File

@ -0,0 +1,25 @@
package org.jeecg.modules.test.feign.fallback;
import org.jeecg.common.api.vo.Result;
import lombok.Setter;
import org.jeecg.modules.test.feign.client.JeecgTestClient;
/**
* 接口fallback实现
*
* @author: scott
* @date: 2022/4/11 19:41
*/
public class JeecgTestFallback implements JeecgTestClient {
@Setter
private Throwable cause;
@Override
public String getMessage(String name) {
return "访问超时, 自定义FallbackFactory";
}
}

View File

@ -0,0 +1,71 @@
package org.jeecg.modules.test.lock;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.boot.starter.lock.annotation.JLock;
import org.jeecg.boot.starter.lock.client.RedissonLockClient;
import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient;
import org.jeecg.common.base.BaseMap;
import org.jeecg.modules.test.constant.CloudConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* 分布式锁测试demo
* @author: zyf
* @date: 2022/04/21
*/
@Slf4j
@Component
public class DemoLockTest {
@Autowired
RedissonLockClient redissonLock;
// @Autowired
// RabbitMqClient rabbitMqClient;
/**
* 测试方法:
* @Scheduled(cron = "0/5 * * * * ?") 表示每5秒执行一次
* @JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1)分布式锁10秒钟才释放
* 结果每10秒钟输出一次 “执行 分布式锁 业务逻辑1” 就说明锁成功了
*
* 测试分布式锁【注解方式】
*/
@Scheduled(cron = "0/5 * * * * ?")
@JLock(lockKey = CloudConstant.REDISSON_DEMO_LOCK_KEY1)
public void execute() throws InterruptedException {
log.info("执行execute任务开始休眠十秒开始当前系统时间戳"+ System.currentTimeMillis()/1000);
Thread.sleep(10000);
log.info("========执行 分布式锁 业务逻辑1=============");
// Map map = new BaseMap();
// map.put("orderId", "BJ0001");
// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map);
// //延迟10秒发送
// map.put("orderId", "NJ0002");
// rabbitMqClient.sendMessage(CloudConstant.MQ_JEECG_PLACE_ORDER, map, 10000);
log.info("execute任务结束休眠十秒完成当前系统时间戳"+ System.currentTimeMillis()/1000);
}
/**
* 测试分布式锁【编码方式】
* @Scheduled(cron = "0/5 * * * * ?")
*/
public void execute2() throws InterruptedException {
int expireSeconds=6000;
if (redissonLock.tryLock(CloudConstant.REDISSON_DEMO_LOCK_KEY2, -1, expireSeconds)) {
log.info("执行任务execute2开始休眠十秒");
Thread.sleep(10000);
log.info("=============业务逻辑2===================");
log.info("定时execute2结束休眠十秒");
redissonLock.unlock(CloudConstant.REDISSON_DEMO_LOCK_KEY2);
} else {
log.info("execute2获取锁失败");
}
}
}

View File

@ -0,0 +1,235 @@
package org.jeecg.modules.test.xxljob;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
/**
* xxl-job定时任务测试
* @author: zyf
* @date: 2022/04/21
*/
@Component
@Slf4j
public class DemoJobHandler {
/**
* 简单任务
*
* @param params
* @return
*/
@XxlJob(value = "demoJob")
public ReturnT<String> demoJobHandler(String params) {
log.info("我是 jeecg-system 服务里的定时任务 demoJob我执行了...............................");
return ReturnT.SUCCESS;
}
/**
* 2、分片广播任务
*/
@XxlJob("shardingJobHandler")
public ReturnT<String> shardingJobHandler(String param) throws Exception {
// 分片参数
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
log.info("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal());
// 业务逻辑
for (int i = 0; i < shardingVO.getTotal(); i++) {
if (i == shardingVO.getIndex()) {
log.info("第 {} 片, 命中分片开始处理", i);
} else {
log.info("第 {} 片, 忽略", i);
}
}
return ReturnT.SUCCESS;
}
/**
* 3、命令行任务
*
* 输入参数ipconfig /all
*/
@XxlJob("commandJobHandler")
public ReturnT<String> commandJobHandler(String param) throws Exception {
String command = param;
int exitValue = -1;
BufferedReader bufferedReader = null;
try {
// command process
Process process = Runtime.getRuntime().exec(command);
BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream());
bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
// command log
String line;
while ((line = bufferedReader.readLine()) != null) {
log.info(line);
}
// command exit
process.waitFor();
exitValue = process.exitValue();
} catch (Exception e) {
log.info(e.getMessage(),e);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
if (exitValue == 0) {
return IJobHandler.SUCCESS;
} else {
return new ReturnT<String>(IJobHandler.FAIL.getCode(), "command exit value(" + exitValue + ") is failed");
}
}
/**
* 4、跨平台Http任务
*
* 输入参数:
* url: https://www.baidu.com
* method: get
* data: content
*/
@XxlJob("httpJobHandler")
public ReturnT<String> httpJobHandler(String param) throws Exception {
String[] methodArray=new String[]{"GET","POST"};
int okState=200;
// param parse
if (param == null || param.trim().length() == 0) {
log.info("param[" + param + "] invalid.");
return ReturnT.FAIL;
}
String[] httpParams = param.split("\n");
String url = null;
String method = null;
String data = null;
for (String httpParam : httpParams) {
if (httpParam.startsWith("url:")) {
url = httpParam.substring(httpParam.indexOf("url:") + 4).trim();
}
if (httpParam.startsWith("method:")) {
method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase();
}
if (httpParam.startsWith("data:")) {
data = httpParam.substring(httpParam.indexOf("data:") + 5).trim();
}
}
// param valid
if (url == null || url.trim().length() == 0) {
log.info("url[" + url + "] invalid.");
return ReturnT.FAIL;
}
if (method == null || !Arrays.asList(methodArray).contains(method)) {
log.info("method[" + method + "] invalid.");
return ReturnT.FAIL;
}
// request
HttpURLConnection connection = null;
BufferedReader bufferedReader = null;
try {
// connection
URL realUrl = new URL(url);
connection = (HttpURLConnection) realUrl.openConnection();
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
connection.setConnectTimeout(3 * 1000);
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
// do connection
connection.connect();
// data
if (data != null && data.trim().length() > 0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();
dataOutputStream.close();
}
// valid StatusCode
int statusCode = connection.getResponseCode();
if (statusCode != okState) {
throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
}
// result
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
String responseMsg = result.toString();
log.info(responseMsg);
return ReturnT.SUCCESS;
} catch (Exception e) {
log.info(e.getMessage(),e);
return ReturnT.FAIL;
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
if (connection != null) {
connection.disconnect();
}
} catch (Exception e2) {
log.info(e2.getMessage(),e2);
}
}
}
/**
* 5、生命周期任务示例任务初始化与销毁时支持自定义相关逻辑
*/
@XxlJob(value = "demoJobHandler2", init = "init", destroy = "destroy")
public ReturnT<String> demoJobHandler2(String param) throws Exception {
log.info("XXL-JOB, Hello World.");
return ReturnT.SUCCESS;
}
public void init() {
log.info("init");
}
public void destroy() {
log.info("destory");
}
}

View File

@ -0,0 +1,41 @@
package org.jeecg.modules.test.xxljob;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* xxl-job定时任务测试
* @author: zyf
* @date: 2022/04/21
*/
@Component
@Slf4j
public class XxclJobTest {
/**
* 简单任务
*
* @param params
* @return
*/
@XxlJob(value = "xxclJobTest")
public ReturnT<String> demoJobHandler(String params) {
log.info("我是 jeecg-system 服务里的定时任务 xxclJobTest , 我执行了...............................");
return ReturnT.SUCCESS;
}
public void init() {
log.info("init");
}
public void destroy() {
log.info("destory");
}
}