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 微服务实战(三):深入微服务架构的进程间通信 微服务实战(四):服务发现的可行方案以及实践案例 微服务实践(五) ...
随机推荐
- 英文写作强调技巧:alliteration, assonance, consonance
alliteration 安排两个以上首字母相同的词相邻 例: The bouncing ball went high into the sky. (In this example, the &quo ...
- nginx+tomcat 下POST响应参数过大无法显示完整及文件下载服务遇到过大文件无法下载解决办法
在nginx里location里面设置 proxy_buffering off; 或者 proxy_buffering on; proxy_buffers 4 4k; proxy_busy_buffe ...
- Django----djagorest-framwork源码剖析
restful(表者征状态转移,面向资源编程)------------------------------------------->约定 从资源的角度审视整个网络,将分布在网络中某个节点的资源 ...
- python中的细节
# 1 # li = ['a', 'b', 'c', 'd','e'] # print(li[10:]) #[] 不报错 # 2 # 这不是True或False,而是值 # 另外,优先级 not &g ...
- Kindle Paper White 使用感受视频上线啦!
大家可以通过以下链接前往我的主页观看视频哦! https://www.youtube.com/watch?v=CESqzxTrAq4&t=322s 欢迎大家点赞.关注! 这期视频用iPhone ...
- CCPC-Wannafly Winter Camp Day3 Div1 - 石头剪刀布 - [带权并查集]
题目链接:https://zhixincode.com/contest/14/problem/I?problem_id=211 样例输入 1 3 5 2 1 1 2 1 2 1 1 2 3 2 1 ...
- GMM-实现聚类的代码示例
Matlab 代码: % GMM code function varargout = gmm(X, K_or_centroids) % input X:N-by-D data matrix % inp ...
- debian配置java环境变量
操作如下 首先从Oracle上下载支持linux的java jdk,然后安装到你系统中, 然后到/home/xxxx/.bashrc文件中加入 # java JAVA_HOME=/xxx/xxxxx ...
- falsk 与 django 钩子方法
falsk 四大钩子方法# 在第一次请求之前调用@app.before_first_requestdef before_first_request(): print("这是第一次请求之前调用 ...
- java 线程(六)死锁
package cn.sasa.demo4; public class ThreadDemo { public static void main(String[] args){ DeadLockRun ...