api-gateway-engine知识点(2)
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)的更多相关文章
- 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 ...
- 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 ...
- [转载] 构建微服务:使用API Gateway
原文: http://mp.weixin.qq.com/s?__biz=MzA5OTAyNzQ2OA==&mid=206889381&idx=1&sn=478ccb35294c ...
- Amazon API Gateway Importer整合过程小结
(1)需要将swagger json转换成amazon api gateway 所需要的格式(根据Method Request中 Request PathsURL Query String Param ...
- 微服务API Gateway
翻译-微服务API Gateway 原文地址:http://microservices.io/patterns/apigateway.html,以下是使用google翻译对原文的翻译. 让我们想象一下 ...
- gRPC helloworld service, RESTful JSON API gateway and swagger UI
概述 本篇博文完整讲述了如果通过 protocol buffers 定义并启动一个 gRPC 服务,然后在 gRPC 服务上提供一个 RESTful JSON API 的反向代理 gateway,最后 ...
- 谈谈微服务中的 API 网关(API Gateway)
前言 又是很久没写博客了,最近一段时间换了新工作,比较忙,所以没有抽出来太多的时间写给关注我的粉丝写一些干货了,就有人问我怎么最近没有更新博客了,在这里给大家抱歉. 那么,在本篇文章中,我们就一起来探 ...
- API Gateway - KONG 安装与配置
简介 Kong,是由Mashape公司开源的,基于Nginx的API gateway 特点 可扩展,支持分布式 模块化 功能:授权.日志.ip限制.限流.api 统计分析(存在商业插件Galileo等 ...
- 分享一个国内首个企业级开源的GO语言网关--GoKu API Gateway
一. 简介 GoKu API Gateway,中文名:悟空API网关,是国内首个开源go语言API网关,帮助企业进行API服务治理与API性能安全维护,为企业数字化赋能. GoKu API Gatew ...
- 微服务实战(二):使用API Gateway
微服务实战(一):微服务架构的优势与不足 微服务实战(二):使用API Gateway 微服务实战(三):深入微服务架构的进程间通信 微服务实战(四):服务发现的可行方案以及实践案例 微服务实践(五) ...
随机推荐
- 更新docker时间-需要重启docker
更新docker时间:1.docker run -d -v /etc/localtime:/etc/localtime:ro [IMAGE] 2.重启,docker-compose up -d 3.d ...
- 学习mongoDB的网站
- [Asp.net]Uploadify上传大文件,Http error 404 解决方案 - wolfy
引言 之前使用Uploadify做了一个上传图片并预览的功能,今天在项目中,要使用该插件上传大文件.之前弄过上传图片的demo,就使用该demo进行测试.可以查看我的这篇文章: [Asp.net]Up ...
- 树剖+线段树||树链剖分||BZOJ2238||Mst
题面:https://www.lydsy.com/JudgeOnline/problem.php?id=2238 思路:先求个最小生成树,然后就对最小生成树上的边做树剖,依次对非树边进行处理,维护非树 ...
- 泡泡一分钟:Towards real-time unsupervised monocular depth estimation on CPU
Towards real-time unsupervised monocular depth estimation on CPU Matteo Poggi , Filippo Aleotti , Fa ...
- 用CSS画基本图形
用CSS画基本图形 1.正方形 代码如下: #square { width: 100px; height: 100px; background: red; } 2.长方形 代码如下: #recta ...
- hive优化之开启压缩功能
1.开启hive作业mapreduce任务中间压缩功能: 对于数据进行压缩可以减少job中map和reduce task间的数据传输量.对于中间数据压缩,选择一个低cpu开销编/解码器要不选择一个压缩 ...
- 进制转换 map
a_z = [i for i in map(chr, range(ord('a'), ord('z') + 1))]'''Address of var1 variable: 240ff24Addres ...
- int 4 bytes
http://waynewhitty.ie/blog-post.php?id=19 MySQL - INT(11) vs BIGINT(11) vs TINYINT(11) This seems to ...
- 使用c#反射实现接口可视化调试页面
直接上代码,引用CommTools.dll.包括aspx显示页面和aspx.cs获取反射数据源代码 using System; using System.Collections.Generic; us ...