nacos加入到项目当中

This commit is contained in:
dengqichen 2024-08-26 13:46:13 +08:00
parent cc813549f3
commit 05a4c87022
4 changed files with 13 additions and 39 deletions

View File

@ -1,29 +0,0 @@
package com.qc.soft.framework.basic.http;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfiguration {
@Bean(name = "stringRedisTemplate")
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(serializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(serializer);
return redisTemplate;
}
}

View File

@ -49,11 +49,11 @@ public class JenkinsDataCacheSynchronizer {
@EventListener(ApplicationReadyEvent.class)
public void firstSyncCheck() {
log.info("The adapter checks if the item is initialized");
ThirdPartyJenkinsResponse redisValue = (ThirdPartyJenkinsResponse) redisTemplate.opsForValue().get(REDIS_JENKINS_ORIGINAL_VIEW);
if (redisValue != null) {
log.info("Instead of initializing the project, the jenkins information will be incrementally synchronized");
return;
}
// ThirdPartyJenkinsResponse redisValue = (ThirdPartyJenkinsResponse) redisTemplate.opsForValue().get(REDIS_JENKINS_ORIGINAL_VIEW);
// if (redisValue != null) {
// log.info("Instead of initializing the project, the jenkins information will be incrementally synchronized");
//// return;
// }
CompletableFuture<Void> future = CompletableFuture.runAsync(this::views, executorService)
.thenRun(this::viewDetail)
.thenRun(this::job)
@ -103,6 +103,9 @@ public class JenkinsDataCacheSynchronizer {
@Scheduled(cron = "15 * * * * ?")
public void job() {
List<ThirdPartyJenkinsViewDetailResponse> cacheViewsDetail = getCacheViewsDetail();
if (CollectionUtils.isEmpty(cacheViewsDetail)) {
return;
}
ExecutorService viewPool = Executors.newFixedThreadPool(cacheViewsDetail.size(), r -> {
Thread thread = new Thread(r);
thread.setName("jenkins-sync-view-thread-" + System.currentTimeMillis());

View File

@ -65,10 +65,10 @@ public class JenkinsController {
// return Flux.interval(Duration.ofSeconds(2)).map(index -> jenkinsService.aggregate());
// }
// @GetMapping(value = "jenkins/aggregate")
// public JenkinsAggregateResponse aggregate() {
// return jenkinsService.aggregate();
// }
@GetMapping(value = "jenkins/aggregate")
public JenkinsAggregateResponse aggregate() {
return jenkinsService.aggregate();
}
//
//
// @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)

View File

@ -100,7 +100,7 @@ public class JenkinsServiceImpl implements IJenkinsService {
}
aggregate.setViews(viewsAggregate);
stopWatch.stop();
log.info("Elapsed time in seconds:{}", stopWatch.getTotalTimeSeconds());
log.info("Jenkins aggregate elapsed time in seconds:{}", stopWatch.getTotalTimeSeconds());
return aggregate;
}