GroupVersion实现engine本地缓存

package com.inspur.cloud.apigw.engine.cache;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.inspur.cloud.apigw.engine.common.RedisCachePrefix;
import com.inspur.cloud.apigw.engine.common.RedisConnectionPool;

import redis.clients.jedis.Jedis;

public class GroupVersionCache {

private static ConcurrentHashMap<String, ConcurrentHashMap<String, String>> cache = new ConcurrentHashMap<String, ConcurrentHashMap<String, String>>();

private GroupVersionCache() {

}

// 初始化redis中的Frtkey到本地cache中
public static void initCache() throws Exception {
Jedis jedis = RedisConnectionPool.getConnection();
try {
Set<String> keys = jedis.keys("API:GrpVer:*");
for (String key : keys) {
ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();
Map<String, String> value = jedis.hgetAll(key);
concurrentHashMap.putAll(value);
cache.put(key, concurrentHashMap);
}
} catch (Exception e) {
throw e;
} finally {
jedis.close();
}
}

// 在本地缓存中,通过groupCode和versionCode获取VersionInfo
public static ConcurrentHashMap<String, String> getVersionInfoByCache(String groupCode, String versionCode)
throws Exception {
try {
String grpVersionKey = RedisCachePrefix.getApiGrpVerKey(groupCode, versionCode);
return cache.get(grpVersionKey);
} catch (Exception e) {
throw e;
}
}

// 版本上线时,向engine本地中增加绑定关系缓存
public static void addVersionInfoToCache(String messageKey, Map<String, String> map) throws Exception {
try {
ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();
concurrentHashMap.putAll(map);
cache.put(messageKey, concurrentHashMap);
} catch (Exception e) {
throw e;
}
}

// 下线时,删除本地缓存中的某条数据
public static void deleteCacheBykey(String messageKey) throws Exception {
try {
cache.remove(messageKey);
} catch (Exception e) {
throw e;
}
}

}

为什么要用 conCurrentHashMap?Map或者HashMap也可以吧?

api-gateway-engine知识点(2)的更多相关文章

  1. Using Amazon API Gateway with microservices deployed on Amazon ECS

    One convenient way to run microservices is to deploy them as Docker containers. Docker containers ar ...

  2. Aws api gateway Domain name

    Set Up a Custom Domain Name for an API Gateway API The following procedure describes how to set up a ...

  3. [转载] 构建微服务:使用API Gateway

    原文: http://mp.weixin.qq.com/s?__biz=MzA5OTAyNzQ2OA==&mid=206889381&idx=1&sn=478ccb35294c ...

  4. Amazon API Gateway Importer整合过程小结

    (1)需要将swagger json转换成amazon api gateway 所需要的格式(根据Method Request中 Request PathsURL Query String Param ...

  5. 微服务API Gateway

    翻译-微服务API Gateway 原文地址:http://microservices.io/patterns/apigateway.html,以下是使用google翻译对原文的翻译. 让我们想象一下 ...

  6. gRPC helloworld service, RESTful JSON API gateway and swagger UI

    概述 本篇博文完整讲述了如果通过 protocol buffers 定义并启动一个 gRPC 服务,然后在 gRPC 服务上提供一个 RESTful JSON API 的反向代理 gateway,最后 ...

  7. 谈谈微服务中的 API 网关(API Gateway)

    前言 又是很久没写博客了,最近一段时间换了新工作,比较忙,所以没有抽出来太多的时间写给关注我的粉丝写一些干货了,就有人问我怎么最近没有更新博客了,在这里给大家抱歉. 那么,在本篇文章中,我们就一起来探 ...

  8. API Gateway - KONG 安装与配置

    简介 Kong,是由Mashape公司开源的,基于Nginx的API gateway 特点 可扩展,支持分布式 模块化 功能:授权.日志.ip限制.限流.api 统计分析(存在商业插件Galileo等 ...

  9. 分享一个国内首个企业级开源的GO语言网关--GoKu API Gateway

    一. 简介 GoKu API Gateway,中文名:悟空API网关,是国内首个开源go语言API网关,帮助企业进行API服务治理与API性能安全维护,为企业数字化赋能. GoKu API Gatew ...

  10. 微服务实战(二):使用API Gateway

    微服务实战(一):微服务架构的优势与不足 微服务实战(二):使用API Gateway 微服务实战(三):深入微服务架构的进程间通信 微服务实战(四):服务发现的可行方案以及实践案例 微服务实践(五) ...

随机推荐

  1. Tiobe最新编程语言排行

    https://www.tiobe.com/tiobe-index/

  2. Go学习笔记(二)搭建Visual Studio Code调试环境

    上一篇 Go学习笔记(一)安装Go语言环境 安装Visual Studio Code 这是目前我觉得最好用的文本编辑器了, https://code.visualstudio.com/ 中间有几部确认 ...

  3. 【CF944G】Coins Exhibition DP+队列

    [CF944G]Coins Exhibition 题意:Jack去年参加了一个珍稀硬币的展览会.Jack记得一共有 $k$ 枚硬币,这些硬币排成一行,从左到右标号为 $1$ 到 $k$ ,每枚硬币是正 ...

  4. golang - interface的作用

    多态.struct 可以赋值给 interface.interface 可以转换成子接口,或者 struct. 请看go中的一段的源代码: listener, _ := net.Listen(&quo ...

  5. python使用selenium安装chromedriver的问题

    环境 win64位,python3.6, 问题与解决 说来也巧,今天无意中解决了两个多月前的问题,即用selenium调用chrome浏览器报错的问题:起因是在知乎中看到了一篇12306抢票的文章,用 ...

  6. Tif文件合并类

    using System; using System.Collections; using System.Collections.Generic; using System.Drawing; usin ...

  7. ie9 form submit 请求参数问题替代办法

    //隐藏表单 <input id="hdPeriod" name="period" type="hidden" value=" ...

  8. linux shutdown命令以及参数详解

    在说shutdown命令之前 先说一下sync命令: sync:将内存中尚未写入硬盘的数据写入硬盘 因为linux为了保证数据读写速度,把常用的数据放在内存中,不会立即写入硬盘,如果有不当关机,这些数 ...

  9. 12.4 hdfs总结

    启动hdfs 需要在namenode 节点 上 s11 启动yarn 需要在resourceManager 节点上 namenode, resourceManager 都需要在整个集群中都是可以无密登 ...

  10. Docker容器与容器云之Docker单机集群部署案例

    准备工作: CentOS 7安装docker: #yum -y install docker 1.获取节点所需镜像 --主机执行 #docker pull django #docker pull ha ...