In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the principle and usage of ServerHttpAgent in nacos client". In daily operation, I believe that many people have doubts about the principle and use of ServerHttpAgent in nacos client. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the principle and usage of ServerHttpAgent in nacos client". Next, please follow the editor to study!
Order
This paper mainly studies the ServerHttpAgent of nacos client.
HttpAgent
Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/config/http/HttpAgent.java
Public interface HttpAgent {/ * * start to get nacos ip list * @ return Nothing. * @ throws NacosException on get ip list error. * / void start () throws NacosException; / * invoke http get method * @ param path http path * @ param paramValues http paramValues http * @ param encoding http encode * @ param readTimeoutMs http timeout * @ return HttpResult http response * @ throws IOException If an input or output exception occurred * / HttpResult httpGet (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException / * invoke http post method * @ param path http path * @ param headers http headers * @ param paramValues http paramValues http * @ param readTimeoutMs http timeout * @ return HttpResult http response * @ throws IOException If an input or output exception occurred * / HttpResult httpPost (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException / * invoke http delete method * @ param path http path * @ param headers http headers * @ param paramValues http paramValues http * @ param readTimeoutMs http timeout * @ return HttpResult http response * @ throws IOException If an input or output exception occurred * / HttpResult httpDelete (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException / * get name * @ return String * / String getName (); / * get namespace * @ return String * / String getNamespace (); / * * get tenant * @ return String * / String getTenant (); / * * get encode * @ return String * / String getEncode ();}
HttpAgent defines start, httpGet, httpPost, httpDelete, getName, getNamespace, getTenant, getEncode methods
ServerHttpAgent
Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/config/http/ServerHttpAgent.java
Public class ServerHttpAgent implements HttpAgent {private static final Logger LOGGER = LogUtils.logger (ServerHttpAgent.class) / * * @ param path relative to web application root Start with / @ param headers * @ param paramValues * @ param encoding * @ param readTimeoutMs * @ return * @ throws IOException * / @ Override public HttpResult httpGet (String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException {final long endTime = System.currentTimeMillis () + readTimeoutMs Final boolean isSSL = false; String currentServerAddr = serverListMgr.getCurrentServerAddr (); int maxRetry = this.maxRetry; do {try {List newHeaders = getSpasHeaders (paramValues); if (headers! = null) {newHeaders.addAll (headers) } HttpResult result = HttpSimpleClient.httpGet (getUrl (currentServerAddr, path), newHeaders, paramValues, encoding, readTimeoutMs, isSSL) If (result.code = = HttpURLConnection.HTTP_INTERNAL_ERROR | | result.code = = HttpURLConnection.HTTP_BAD_GATEWAY | | result.code = = HttpURLConnection.HTTP_UNAVAILABLE) {LOGGER.error ("[NACOS ConnectException] currentServerAddr: {}, httpCode: {}", serverListMgr.getCurrentServerAddr (), result.code) } else {/ / Update the currently available server addr serverListMgr.updateCurrentServerAddr (currentServerAddr); return result;}} catch (ConnectException ce) {LOGGER.error ("[NACOS ConnectException httpGet] currentServerAddr: {}, err: {}", serverListMgr.getCurrentServerAddr (), ce.getMessage ()) } catch (SocketTimeoutException stoe) {LOGGER.error ("[NACOS SocketTimeoutException httpGet] currentServerAddr: {}, err: {}", serverListMgr.getCurrentServerAddr (), stoe.getMessage ());} catch (IOException ioe) {LOGGER.error ("[NACOS IOException httpGet] currentServerAddr:" + serverListMgr.getCurrentServerAddr (), ioe); throw ioe } if (serverListMgr.getIterator (). HasNext ()) {currentServerAddr = serverListMgr.getIterator () .next ();} else {maxRetry -; if (maxRetry < 0) {throw new ConnectException ("[NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached") } serverListMgr.refreshCurrentServerAddr ();}} while (System.currentTimeMillis ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.