2024-12-06 | dengzedong | |
2024-12-06 | dengzedong | |
2024-12-06 | dengzedong | |
2024-12-06 | dengzedong | |
2024-12-06 | dengzedong | |
2024-12-05 | liriming | |
2024-12-04 | liriming | |
2024-12-04 | liriming |
shasteel-biz/pom.xml
@@ -44,6 +44,7 @@ <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-biz-tenant</artifactId> <version>${revision}</version> </dependency> <dependency> @@ -125,13 +126,6 @@ <artifactId>HikariCP-java6</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.3.2</version> </dependency> <dependency> shasteel-biz/src/main/java/com/iailab/module/shasteel/config/FeignTokenInterceptor.java
@@ -3,6 +3,7 @@ import com.iailab.module.shasteel.util.token.IailabClient; import feign.RequestInterceptor; import feign.RequestTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.web.context.request.RequestContextHolder; @@ -11,6 +12,9 @@ @Configuration public class FeignTokenInterceptor implements RequestInterceptor { @Autowired private IailabClient iailabClient; @Override public void apply(RequestTemplate requestTemplate) { // 从当前请求上下文中获取Token @@ -18,16 +22,14 @@ if (token == null) { // 如果没有获取到Token,从system-server中获取token token = IailabClient.getToken(); } if (token!= null) { requestTemplate.header(HttpHeaders.AUTHORIZATION, token); } Long tenantId = IailabClient.getTenantId(); if (tenantId != null) { requestTemplate.header("tenant-id", String.valueOf(tenantId)); token = iailabClient.getToken(); if (token!= null) { requestTemplate.header(HttpHeaders.AUTHORIZATION, token); } Long tenantId = iailabClient.getTenantId(); if (tenantId != null) { requestTemplate.header("tenant-id", String.valueOf(tenantId)); } } } shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunPredictModuleTask.java
@@ -1,12 +1,18 @@ package com.iailab.module.shasteel.job.task; import com.iailab.module.model.api.mdk.MdkApi; import com.iailab.module.model.api.mdk.dto.MdkPredictModuleRespDTO; import com.iailab.module.model.api.mdk.dto.MdkPredictReqDTO; import com.iailab.module.shasteel.mq.common.RoutingConstant; import com.iailab.module.shasteel.mq.consumer.AlarmMessage; import com.iailab.module.shasteel.mq.consumer.PredictFinishMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.Calendar; /** @@ -18,7 +24,9 @@ private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired MdkApi mdkApi; private MdkApi mdkApi; @Autowired private RabbitTemplate rabbitTemplate; @Override @@ -32,9 +40,9 @@ MdkPredictReqDTO dto = new MdkPredictReqDTO(); dto.setPredictTime(calendar.getTime()); dto.setModuleType(params); mdkApi.predictModule(dto); logger.info(params + "模块预测完成"); MdkPredictModuleRespDTO mdkPredictModuleRespDTO = mdkApi.predictModule(dto); logger.info(params + "模块预测完成," + mdkPredictModuleRespDTO); rabbitTemplate.convertAndSend(PredictFinishMessage.EXCHANGE, PredictFinishMessage.PREDICTFINISH_ROUTING_KEY, mdkPredictModuleRespDTO); } catch (Exception ex) { logger.error("runPredictModuleTask运行异常"); shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleModuleTask.java
对比新文件 @@ -0,0 +1,45 @@ package com.iailab.module.shasteel.job.task; import com.iailab.module.model.api.mdk.MdkApi; import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Calendar; /** * 执行调度方案定时任务 * */ @Component("runScheduleModuleTask") public class RunScheduleModuleTask implements ITask { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private MdkApi mdkApi; @Override public void run(String params) { logger.info("runScheduleModuleTask定时任务正在执行,参数为:{}",params ); try { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.SECOND,0); calendar.set(Calendar.MILLISECOND,0); MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); dto.setScheduleTime(calendar.getTime()); dto.setScheduleCode(params); MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); logger.info(params + "调度方案执行完成," + mdkScheduleRespDTO); } catch (Exception ex) { logger.error("runScheduleModuleTask运行异常"); ex.printStackTrace(); } logger.info("runScheduleModuleTask运行完成"); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicAlarmRabbitConfig.java
对比新文件 @@ -0,0 +1,37 @@ package com.iailab.module.shasteel.mq.config; import com.iailab.module.shasteel.mq.consumer.AlarmMessage; import com.iailab.module.shasteel.mq.consumer.PredictFinishMessage; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; import org.springframework.amqp.core.Queue; import org.springframework.amqp.core.TopicExchange; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @Configuration public class TopicAlarmRabbitConfig { //绑定键 public final static String routingAlarm = AlarmMessage.ALARM_ROUTING_KEY; @Bean public Queue alarmQueue() { return new Queue(TopicAlarmRabbitConfig.routingAlarm); } @Bean TopicExchange alarmExchange() { return new TopicExchange(AlarmMessage.EXCHANGE); } // 注意通配符*和#的用法 @Bean Binding bindingExchangeMessageAlarm() { return BindingBuilder.bind(alarmQueue()).to(alarmExchange()).with(routingAlarm); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicPredictFinishRabbitConfig.java
@@ -23,15 +23,14 @@ return new Queue(TopicPredictFinishRabbitConfig.routingPredictFinish); } @Bean TopicExchange exchange() { TopicExchange predictFinishExchange() { return new TopicExchange(PredictFinishMessage.EXCHANGE); } // 注意通配符*和#的用法 @Bean Binding bindingExchangeMessageDH() { return BindingBuilder.bind(predictFinishQueue()).to(exchange()).with(routingPredictFinish); Binding bindingExchangeMessagePF() { return BindingBuilder.bind(predictFinishQueue()).to(predictFinishExchange()).with(routingPredictFinish); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmConsumer.java
对比新文件 @@ -0,0 +1,37 @@ package com.iailab.module.shasteel.mq.consumer; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.api.mcs.McsApi; import com.iailab.module.model.api.mcs.dto.AlarmConfigRespDTO; import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; import com.iailab.module.model.api.mcs.dto.PreDataJsonReqVO; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @Component @RabbitListener(queues = AlarmMessage.ALARM_ROUTING_KEY) public class AlarmConsumer { @Resource private RabbitTemplate rabbitTemplate; public void process(AlarmMessage alarmMessage) throws InterruptedException { rabbitTemplate.convertAndSend(AlarmMessage.EXCHANGE, AlarmMessage.ALARM_ROUTING_KEY, alarmMessage); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmMessage.java
@@ -9,7 +9,7 @@ @Data public class AlarmMessage implements Serializable { public static final String EXCHANGE = "alarm-exchange"; public static final String EXCHANGE = "predict-alarm-exchange"; public static final String ALARM_ROUTING_KEY = RoutingConstant.Iailab_Model_Alarm; // 预警消息DTO shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
@@ -1,6 +1,5 @@ package com.iailab.module.shasteel.mq.consumer; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.api.mcs.McsApi; @@ -9,14 +8,15 @@ import com.iailab.module.model.api.mcs.dto.PreDataJsonReqVO; 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 org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lirm @@ -31,13 +31,12 @@ private McsApi mcsApi; @Resource private RabbitTemplate rabbitTemplate; private AlarmConsumer alarmConsumer; @RabbitHandler public void process(PredictFinishMessage finishMessage) throws InterruptedException { public void process(JSONObject json) throws InterruptedException { System.out.println("测试消费模型预测完成RabbitMQ消息----------------------"); Thread.sleep(5000); List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(new HashMap<String, Object>()); if (!CollectionUtils.isEmpty(configList)) { List<String> OutputIdList = new ArrayList<>(); @@ -45,37 +44,44 @@ OutputIdList.add(item.getOutId()); }); configList.forEach(item -> { PreDataJsonReqVO preDataJsonReqVO = new PreDataJsonReqVO(); preDataJsonReqVO.setPredictTime(finishMessage.getPredictTime()); preDataJsonReqVO.setOutputIdList(OutputIdList); Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(preDataJsonReqVO); PreDataJsonReqVO reqVO = new PreDataJsonReqVO(); reqVO.setPredictTime(DateUtils.parse(json.get("predictTime").toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); reqVO.setOutputIdList(OutputIdList); Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO); if (!CollectionUtils.isEmpty(preData)) { List<Object[]> result = preData.get(item.getOutId()); int toIndex = result.size(); int fromIndex = result.size() - item.getCompLength(); List<Object[]> predictList = result.subList(fromIndex, toIndex); for(Object[] data : predictList){ BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP); if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) { AlarmMessage alarmMessage = new AlarmMessage(); AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); alarmMessageRespDTO.setConfigId(item.getId()); if (dataValue.compareTo(item.getLowerLimit()) < 0) { alarmMessageRespDTO.setAlarmType("1");//超下限 }else if (dataValue.compareTo(item.getUpperLimit()) > 0) { alarmMessageRespDTO.setAlarmType("2");//超上限 if(toIndex > 0){ int fromIndex = result.size() - item.getCompLength(); List<Object[]> predictList = result.subList(fromIndex, toIndex); for(Object[] data : predictList){ BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP); if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) { AlarmMessage alarmMessage = new AlarmMessage(); AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); alarmMessageRespDTO.setConfigId(item.getId()); if (dataValue.compareTo(item.getLowerLimit()) < 0) { alarmMessageRespDTO.setAlarmType("1");//超下限 }else if (dataValue.compareTo(item.getUpperLimit()) > 0) { alarmMessageRespDTO.setAlarmType("2");//超上限 } alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); JSONObject content = new JSONObject(); content.put("alarmObj", item.getAlarmObj()); content.put("alarmType", alarmMessageRespDTO.getAlarmType()); content.put("unit", item.getUnit()); content.put("overLimitTime", data[0]); content.put("overLimitValue", dataValue); alarmMessageRespDTO.setContent(JSONObject.toJSONString(content)); System.out.println("预警消息=" + alarmMessageRespDTO); alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO); try { alarmConsumer.process(alarmMessage); } catch (InterruptedException e) { throw new RuntimeException(e); } break; } alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); JSONObject content = new JSONObject(); content.put("alarmObj", item.getAlarmObj()); content.put("alarmType", alarmMessageRespDTO.getAlarmType()); content.put("unit", item.getUnit()); content.put("overLimitTime", data[0]); content.put("overLimitValue", dataValue); alarmMessageRespDTO.setContent(JSONObject.toJSONString(content)); alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO); rabbitTemplate.convertAndSend(AlarmMessage.EXCHANGE, AlarmMessage.ALARM_ROUTING_KEY, alarmMessage); break; } } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleConsumer.java
对比新文件 @@ -0,0 +1,56 @@ package com.iailab.module.shasteel.mq.consumer; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iailab.module.model.api.mcs.McsApi; import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; import com.iailab.module.model.api.mdk.MdkApi; import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @Component @RabbitListener(queues = AlarmMessage.ALARM_ROUTING_KEY) public class ScheduleConsumer { @Resource private McsApi mcsApi; @Resource private MdkApi mdkApi; @RabbitHandler public void process(AlarmMessage alarmMessage) { Map<String, Object> params = new HashMap<>(); params.put("trigger_condition", AlarmMessage.ALARM_ROUTING_KEY); List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(params);//根据触发条件获取调度方案列表 for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){ MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO(); mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode()); mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime()); // MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案 // String result = mdkScheduleRespDTO.getResult().toString(); // System.out.println(result); // AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); // mcsApi.createAlarmMessage(alarmMessageRespDTO); } // AlarmMessageRespDTO alarmMessageRespDTO = alarmMessage.getAlarmMessageRespDTO(); // JSONObject contentJson = JSONObject.parseObject(alarmMessageRespDTO.getContent()); // String overLimitTime = contentJson.get("overLimitTime").toString(); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleMessage.java
对比新文件 @@ -0,0 +1,17 @@ package com.iailab.module.shasteel.mq.consumer; import com.iailab.module.shasteel.mq.common.RoutingConstant; import lombok.Data; import java.io.Serializable; import java.util.Date; @Data public class ScheduleMessage implements Serializable { public static final String EXCHANGE = "schedule-exchange"; public static final String SCHEDULE_ROUTING_KEY = RoutingConstant.Iailab_Model_PredictFinish; // 预测时间 private Date predictTime; } shasteel-biz/src/main/java/com/iailab/module/shasteel/util/token/IailabClient.java
@@ -1,11 +1,13 @@ package com.iailab.module.shasteel.util.token; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.Base64Utils; import org.springframework.util.ObjectUtils; @@ -20,25 +22,32 @@ * @createTime 2024年11月21日 */ @Slf4j @Component public class IailabClient { /** * 平台地址 */ public static String BASE_URL; @Value("${iailab.token.base-url}") private String BASE_URL; /** * 租户编号 */ public static Long TENANT_ID; @Value("${iailab.token.tenant-id}") private String TENANT_ID; /** * 客户端信息 */ private static String CLIENT_ID; private static String CLIENT_SECRET; private static String USERNAME; private static String PASSWORD; @Value("${iailab.token.client-id}") private String CLIENT_ID; @Value("${iailab.token.client-secret}") private String CLIENT_SECRET; @Value("${iailab.token.username}") private String USERNAME; @Value("${iailab.token.password}") private String PASSWORD; private static final String GRAND_TYPE = "password"; private static final String SCOPE = "user.read user.write"; @@ -46,38 +55,16 @@ private static final RestTemplate restTemplate = new RestTemplate(); // 鉴权token public static String accessToken; private String accessToken; // 刷新token public static String refreshToken; private String refreshToken; // 鉴权token过期时间 public static Long expireTime; private static final IailabClient iailabClient = new IailabClient(); private IailabClient() { // BASE_URL = PlatApplicationContext.getProperty("iailab.baseUrl"); // TENANT_ID = Long.parseLong(PlatApplicationContext.getProperty("iailab.tenantId")); // CLIENT_ID = PlatApplicationContext.getProperty("iailab.clientId"); // CLIENT_SECRET = PlatApplicationContext.getProperty("iailab.clientSecret"); // USERNAME = PlatApplicationContext.getProperty("iailab.username"); // PASSWORD = PlatApplicationContext.getProperty("iailab.password"); BASE_URL = "http://127.0.0.1:48080/admin-api/system"; TENANT_ID = 172L; CLIENT_ID = "shasteel"; CLIENT_SECRET = "shasteel111111111111111"; USERNAME = "shasteel"; PASSWORD = "123456"; } public static IailabClient getInstance() { return iailabClient; } private Long expireTime; /** * 用户名密码方式获取平台token */ private static synchronized void authenticate() { private synchronized void authenticate() { log.info("获取平台token"); // 1.1 构建请求头 HttpHeaders headers = new HttpHeaders(); @@ -104,7 +91,7 @@ expireTime = Long.valueOf(authMap.get("expires_time").toString()); } private static synchronized void refreshToken() { private synchronized void refreshToken() { log.info("刷新token"); // 1.1 构建请求头 HttpHeaders headers = new HttpHeaders(); @@ -133,26 +120,26 @@ } } private static void addClientHeader(HttpHeaders headers) { private void addClientHeader(HttpHeaders headers) { // client 拼接,需要 BASE64 编码 String client = CLIENT_ID + ":" + CLIENT_SECRET; client = Base64Utils.encodeToString(client.getBytes(StandardCharsets.UTF_8)); headers.add("Authorization", "Basic " + client); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.set("tenant-id", TENANT_ID.toString()); headers.set("tenant-id", getTenantId().toString()); } public static String getToken() { public String getToken() { //第一次请求或者token过期,需要重新获取token if(ObjectUtils.isEmpty(IailabClient.accessToken)) { IailabClient.authenticate(); } else if (IailabClient.expireTime < System.currentTimeMillis() / 1000) { IailabClient.refreshToken(); if(ObjectUtils.isEmpty(accessToken)) { authenticate(); } else if (expireTime < System.currentTimeMillis() / 1000) { refreshToken(); } return accessToken; } public static Long getTenantId() { return TENANT_ID; public Long getTenantId() { return Long.valueOf(TENANT_ID); } } shasteel-biz/src/main/resources/application-dev.yaml
@@ -35,21 +35,16 @@ primary: master datasource: master: url: jdbc:mysql://172.16.8.100:3306/iailab_expert_tenant_shasteel?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 username: root password: 123456 slave: # 模拟从库,可根据自己需要修改 lazy: true # 开启懒加载,保证启动速度 url: jdbc:mysql://127.0.0.1:3306/iailab_expert_tenant_shasteel?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true url: jdbc:mysql://127.0.0.1:3306/iailab_expert_tenant_shasteel?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 username: root password: 123456 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: host: 172.16.8.100 # 地址 host: 127.0.0.1 # 地址 port: 6379 # 端口 database: 8 # 数据库索引 password: 123456 # 密码,建议生产环境开启 database: 0 # 数据库索引 # password: 123456 # 密码,建议生产环境开启 --- #################### MQ 消息队列相关配置 #################### @@ -60,10 +55,10 @@ spring: # RabbitMQ 配置项,对应 RabbitProperties 配置类 rabbitmq: host: 172.16.8.200 # RabbitMQ 服务的地址 host: 127.0.0.1 # RabbitMQ 服务的地址 port: 5672 # RabbitMQ 服务的端口 username: admin # RabbitMQ 服务的账号 password: admin123 # RabbitMQ 服务的密码 username: guest # RabbitMQ 服务的账号 password: guest # RabbitMQ 服务的密码 # Kafka 配置项,对应 KafkaProperties 配置类 kafka: bootstrap-servers: 127.0.0.1:9092 # 指定 Kafka Broker 地址,可以设置多个,以逗号分隔 @@ -80,4 +75,11 @@ mock-enable: true access-log: # 访问日志的配置项 enable: false token: base-url: http://127.0.0.1:48080/admin-api/system tenant-id: 172 client-id: shasteel client-secret: shasteel111111111111111 username: shasteel password: 123456 shasteel-biz/src/main/resources/application-test.yaml
@@ -79,4 +79,11 @@ send-maximum-quantity-per-day: 10 begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 end-code: 9999 # 这里配置 9999 的原因是,测试方便。 token: base-url: http://172.16.8.100:48080/admin-api/system tenant-id: 172 client-id: shasteel client-secret: shasteel111111111111111 username: shasteel password: 123456 shasteel-biz/src/main/resources/logback-spring.xml
@@ -57,15 +57,15 @@ </appender> <!-- 本地环境 --> <springProfile name="local"> <root level="INFO"> <springProfile name="dev"> <root level="DEBUG"> <appender-ref ref="STDOUT"/> <appender-ref ref="GRPC"/> <!-- 本地环境下,如果不想接入 SkyWalking 日志服务,可以注释掉本行 --> <appender-ref ref="ASYNC"/> <!-- 本地环境下,如果不想打印日志,可以注释掉本行 --> </root> </springProfile> <!-- 其它环境 --> <springProfile name="dev,test,stage,prod,default"> <springProfile name="test,stage,prod,default"> <root level="INFO"> <appender-ref ref="STDOUT"/> <appender-ref ref="ASYNC"/> shasteel-biz/src/test/java/com/iailab/module/data/controller/RabbitMQTest.java
对比新文件 @@ -0,0 +1,33 @@ package com.iailab.module.data.controller; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.framework.test.core.ut.BaseMockitoUnitTest; import com.iailab.module.shasteel.ShasteelServerApplication; import com.iailab.module.shasteel.mq.consumer.PredictFinishMessage; import org.junit.jupiter.api.Test; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.util.Date; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @SpringBootTest(classes = ShasteelServerApplication.class) public class RabbitMQTest extends BaseMockitoUnitTest { @Resource private RabbitTemplate rabbitTemplate; @Test public void testProducer() { JSONObject content = new JSONObject(); content.put("moduleType", "NET_LDG"); content.put("predictTime", "2024-12-04 06:30:00"); rabbitTemplate.convertAndSend(PredictFinishMessage.EXCHANGE, PredictFinishMessage.PREDICTFINISH_ROUTING_KEY, content); } } shasteel-biz/src/test/java/com/iailab/module/package-info.java
对比新文件 @@ -0,0 +1 @@ package com.iailab.module;