爲何要將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();
}
}