为什么要将map转为set?
因为map是存的键值对,转为set后,可以进行遍历,这样就可以将map中的所有键值对都取出来。
SetkeySet = map.keySet();
/** * 获取WebSocket * @param user */ public static WebSocket getWebSocketByUser(String user){ SetkeySet = userconnections.keySet(); synchronized (keySet) { //对象加锁,锁住的是这个对象,而不是代码。 for (WebSocket conn : keySet) { String cuser = userconnections.get(conn); if(cuser.equals(user)){ return conn; } } } return null; }
对象加锁,锁住的是这个对象,而不是代码。
------------配置阿里云镜像(因为要访问国外服务器,会很慢)
参考:https://blog.csdn.net/AmaniZ/article/details/79284853
在settings.xml文件中的mirrors下添加mirror标签
<mirror>
<id>alimavenid>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
<mirrorOf>centralmirrorOf>
mirror>
-----------------spring boot-----log4j2--------------
https://www.cnblogs.com/yumi3322/p/7099295.html
https://blog.51cto.com/wyait/1969613
限流
https://blog.csdn.net/ta_ab/article/details/77984312
https://www.jianshu.com/p/d165e12df1da
https://blog.csdn.net/tracy38/article/details/78685707
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
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();
}
}