为何要将map转为set?
html
由于map是存的键值对,转为set后,能够进行遍历,这样就能够将map中的全部键值对都取出来。java
Set<WebSocket> keySet = map.keySet();
/** * 获取WebSocket * @param user */ public static WebSocket getWebSocketByUser(String user){ Set<WebSocket> keySet = userconnections.keySet(); synchronized (keySet) { //对象加锁,锁住的是这个对象,而不是代码。 for (WebSocket conn : keySet) { String cuser = userconnections.get(conn); if(cuser.equals(user)){ return conn; } } } return null; }
对象加锁,锁住的是这个对象,而不是代码。git
------------配置阿里云镜像(由于要访问国外服务器,会很慢)
github
参考:https://blog.csdn.net/AmaniZ/article/details/79284853spring
在settings.xml文件中的mirrors下添加mirror标签数据库
<mirror> 服务器
<id>alimaven</id> app
<name>aliyun maven</name> 异步
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> maven
<mirrorOf>central</mirrorOf>
</mirror>
-----------------spring boot-----log4j2--------------
https://www.cnblogs.com/yumi3322/p/7099295.html
https://blog.51cto.com/wyait/1969613
限流
http://www.javashuo.com/article/p-gcxacedn-gr.html
https://www.jianshu.com/p/d165e12df1da
http://www.javashuo.com/article/p-nmwzreof-en.html
https://www.jianshu.com/p/5246ca996360
https://github.com/marcosbarbero/spring-cloud-zuul-ratelimit
zuul综合:
https://blog.csdn.net/baidu_36415076/article/details/79533572
异步日志到数据库
https://blog.csdn.net/cn_hhaip/article/details/77970349
zuul: ratelimit: enabled: true behind-proxy: true policy-list: user-service: - limit: 10 refresh-interval: 60 type: - user - origin - url
先测试这个:
https://blog.csdn.net/ta_ab/article/details/77984312
public class MyPreFilter implements RateLimitKeyGenerator {
/**
* 以上粒度自由组合,又能够支持多种状况。
* type:
- user
- url
*/
@Override
public String key(HttpServletRequest request, Route route, Policy policy) {
final List<Type> types = policy.getType();
final StringJoiner joiner = new StringJoiner();
joiner.join(RateLimitProperties.PREFIX);
if (route != null) {
joiner.join(route.getId());
}
if (!types.isEmpty()) {
if (types.contains(Type.URL) && route != null) {
joiner.join(route.getPath());
}
if (types.contains(Type.ORIGIN)) {
joiner.join(getRemoteAddr(request));
}
// 这个结合文末总结。判断用户等级,若是不是VIP用户,那么就限制10个,若是是VIP用户就限制100个。
if (types.contains(Type.USER)) {
joiner.join(request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : ANONYMOUS_USER);
}
}
return joiner.toString();
}
}