Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of getServicesOfServer in NacosNamingService

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the role of getServicesOfServer in NacosNamingService. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

NacosNamingService

Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java

Public class NacosNamingService implements NamingService {private static final String DEFAULT_PORT = "8080"; private static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis (5); / * * Each Naming instance should have different namespace. * / private String namespace; private String endpoint; private String serverList; private String cacheDir; private String logName; private HostReactor hostReactor; private BeatReactor beatReactor; private EventDispatcher eventDispatcher; private NamingProxy serverProxy; / /. @ Override public ListView getServicesOfServer (int pageNo, int pageSize) throws NacosException {return serverProxy.getServiceList (pageNo, pageSize, Constants.DEFAULT_GROUP);} @ Override public ListView getServicesOfServer (int pageNo, int pageSize, String groupName) throws NacosException {return getServicesOfServer (pageNo, pageSize, groupName, null);} @ Override public ListView getServicesOfServer (int pageNo, int pageSize, AbstractSelector selector) throws NacosException {return getServicesOfServer (pageNo, pageSize, Constants.DEFAULT_GROUP, selector) } @ Override public ListView getServicesOfServer (int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {return serverProxy.getServiceList (pageNo, pageSize, groupName, selector);} /.}

The getServicesOfServer method requests serverProxy.getServiceList, whose pageNo starts at 1

NamingProxy

Nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java

Public class NamingProxy {private static final int DEFAULT_SERVER_PORT = 8848; private int serverPort = DEFAULT_SERVER_PORT; private String namespaceId; private String endpoint; private String nacosDomain; private List serverList; private List serversFromEndpoint = new ArrayList (); private long lastSrvRefTime = 0L; private long vipSrvRefInterMillis = TimeUnit.SECONDS.toMillis (30); private Properties properties; / /. Public ListView getServiceList (int pageNo, int pageSize, String groupName) throws NacosException {return getServiceList (pageNo, pageSize, groupName, null);} public ListView getServiceList (int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {Map params = new HashMap (4); params.put ("pageNo", String.valueOf (pageNo)); params.put ("pageSize", String.valueOf (pageSize)); params.put (CommonParams.NAMESPACE_ID, namespaceId) Params.put (CommonParams.GROUP_NAME, groupName); if (selector! = null) {switch (SelectorType.valueOf (selector.getType () {case none: break; case label: ExpressionSelector expressionSelector = (ExpressionSelector) selector; params.put ("selector", JSON.toJSONString (expressionSelector)) Break; default: break;}} String result = reqAPI (UtilAndComs.NACOS_URL_BASE + "/ service/list", params); JSONObject json = JSON.parseObject (result); ListView listView = new ListView (); listView.setCount (json.getInteger ("count")) ListView.setData (JSON.parseObject (json.getString ("doms"), new TypeReference () {})); return listView;} / /.}

The getServiceList method of NamingProxy requests the / service/list interface, which assembles the returned data into a ListView structure

ListView

Nacos-1.1.3/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ListView.java

Public class ListView {private List data; private int count; public List getData () {return data;} public void setData (List data) {this.data = data;} public int getCount () {return count;} public void setCount (int count) {this.count = count;} @ Override public String toString () {return JSON.toJSONString (this);}}

ListView contains the count attribute and the data attribute of type List

Summary

The getServicesOfServer method of NacosNamingService requests serverProxy.getServiceList, and its pageNo starts at 1; the getServiceList method of NamingProxy requests the / service/list interface, which assembles the returned data into a ListView structure; ListView contains the count attribute and the data attribute of type List

After reading the above, do you have any further understanding of the role of getServicesOfServer in NacosNamingService? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report