Browse Source

调整接口和熔断器

houweiyu 4 years ago
parent
commit
a21b563ee4

+ 9 - 6
src/main/java/fcb/project/manager/base/utils/FcbUtils.java

@@ -3,6 +3,7 @@ package fcb.project.manager.base.utils;
 import com.alibaba.fastjson.JSON;
 import fdage.back.sdk.base.entity.Result;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -40,12 +41,14 @@ public class FcbUtils {
         }
         long timeStamp = Instant.now().getEpochSecond();
         Instant stepOneStart = Instant.now();
-        String redisKey = JSON.toJSONString(params) + timeStamp;
+        String redisKey = JSON.toJSONString(params);
         if(redisTemplate.hasKey(redisKey)){
             log.info("缓存中存在,直接返回");
-            Map<String , Object> resultMp  = (Map<String, Object>) redisTemplate.opsForValue().get(redisKey);
-            return Result.success(resultMp);
-
+            String redisMapStr = (String) redisTemplate.opsForValue().get(redisKey);
+            if(StringUtils.isNotBlank(redisMapStr)){
+                Map<String , Object> resultMp  = JSON.parseObject(redisMapStr , Map.class);
+                return Result.success(resultMp);
+            }
         }
         Instant stepOneEnd = Instant.now();
         long stepOneDuration = Duration.between(stepOneStart , stepOneEnd).toMillis();
@@ -76,8 +79,8 @@ public class FcbUtils {
         Map<String , Object> resultMap = new HashMap<>();
         resultMap.put("authcode" , md5EncryptionStr);
         resultMap.put("timeStamp" , timeStamp);
-        //缓存一秒
-        redisTemplate.opsForValue().set(redisKey , JSON.toJSONString(resultMap) , 1000 , TimeUnit.MILLISECONDS);
+        //缓存3min
+        redisTemplate.opsForValue().set(redisKey , JSON.toJSONString(resultMap) , 180 , TimeUnit.SECONDS);
         Instant stepThreeEnd = Instant.now();
         long stepThreeDuration = Duration.between(stepThreeStart , stepThreeEnd).toMillis();
         log.info("步骤3耗时:{}" , stepThreeDuration);

+ 0 - 12
src/main/java/fcb/project/manager/core/controller/ApiQueryHouseController.java

@@ -42,23 +42,11 @@ public class ApiQueryHouseController {
 
     @HystrixCommand(commandProperties = {
             @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500"),
-            // 设置统计窗口的桶数量
-            @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "10"),
-            // 设置统计窗口的总时间。每个桶时间 = 总时间 / 桶数量。
-            // 该案例中每个桶时间 = 10000 / 10(ms) = 1000ms
-            // 每个bucket包含success,failure,timeout,rejection的次数的统计信息
-            @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "10000")
     },
             threadPoolProperties = {
                     @HystrixProperty(name = "coreSize", value = "300"),
                     // BlockingQueue的最大队列数,当设为-1,会使用SynchronousQueue,值为正时使用LinkedBlockingQueue。
                     @HystrixProperty(name = "maxQueueSize", value = "200"),
-                    // 设置存活时间,单位分钟。如果coreSize小于maximumSize,那么该属性控制一个线程从实用完成到被释放的时间.
-                    @HystrixProperty(name = "keepAliveTimeMinutes", value = "2"),
-                    // 设置队列拒绝的阈值,即使maxQueueSize还没有达到
-                    @HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"),
-                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "10"),
-                    @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "10000")
             })
     @ApiOperation(value = "获取房车宝的签名")
     @PostMapping("/authCode")