当前位置: 首页 > news >正文

用模板做的网站权重高吗app推广方式

用模板做的网站权重高吗,app推广方式,音乐APP网站开发,html5简单网页源代码本文收录于专栏 Nacos 中 。 文章目录 前言确定前端路由CatalogController.listDetail()ServiceManager总结 前言 前文我们分析了Nacos中客户端注册时数据分发的设计链路,本文根据Nacos前端页面请求,看下前端页面中的服务列表的数据源于哪里。 确定前端…

本文收录于专栏 Nacos 中 。

文章目录

  • 前言
  • 确定前端路由
  • CatalogController.listDetail()
  • ServiceManager
  • 总结


前言

前文我们分析了Nacos中客户端注册时数据分发的设计链路,本文根据Nacos前端页面请求,看下前端页面中的服务列表的数据源于哪里。

确定前端路由

我们已经向Nacos中注册了一个服务,现在去前端确定查询的路由是什么
在这里插入图片描述
确定前端请求路由:/nacos/v1/ns/catalog/services
通过路由确定后端代码位置:

package com.alibaba.nacos.naming.controllers;
CatalogController.listDetail()

CatalogController.listDetail()

/*** List service detail information.** @param withInstances     whether return instances* @param namespaceId       namespace id* @param pageNo            number of page* @param pageSize          size of each page* @param serviceName       service name* @param groupName         group name* @param containedInstance instance name pattern which will be contained in detail* @param hasIpCount        whether filter services with empty instance* @return list service detail*/
@Secured(action = ActionTypes.READ)
@GetMapping("/services")
public Object listDetail(@RequestParam(required = false) boolean withInstances,@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,@RequestParam(required = false) int pageNo, @RequestParam(required = false) int pageSize,@RequestParam(name = "serviceNameParam", defaultValue = StringUtils.EMPTY) String serviceName,@RequestParam(name = "groupNameParam", defaultValue = StringUtils.EMPTY) String groupName,@RequestParam(name = "instance", defaultValue = StringUtils.EMPTY) String containedInstance,@RequestParam(required = false) boolean hasIpCount) throws NacosException {//前端withInstances传的是false,不走这个分支if (withInstances) {return judgeCatalogService().pageListServiceDetail(namespaceId, groupName, serviceName, pageNo, pageSize);}//确定是走的这里获取的服务列表return judgeCatalogService().pageListService(namespaceId, groupName, serviceName, pageNo, pageSize, containedInstance, hasIpCount);
}

查看judgeCatalogService().pageListService(namespaceId, groupName, serviceName, pageNo, pageSize, containedInstance, hasIpCount);的实现:

@Override
public Object pageListService(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize,String instancePattern, boolean ignoreEmptyService) throws NacosException {ObjectNode result = JacksonUtils.createEmptyJsonNode();List<ServiceView> serviceViews = new LinkedList<>();//获取服务列表Collection<Service> services = patternServices(namespaceId, groupName, serviceName);if (ignoreEmptyService) {services = services.stream().filter(each -> 0 != serviceStorage.getData(each).ipCount()).collect(Collectors.toList());}result.put(FieldsConstants.COUNT, services.size());services = doPage(services, pageNo - 1, pageSize);for (Service each : services) {ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(each).orElseGet(ServiceMetadata::new);ServiceView serviceView = new ServiceView();serviceView.setName(each.getName());serviceView.setGroupName(each.getGroup());serviceView.setClusterCount(serviceStorage.getClusters(each).size());serviceView.setIpCount(serviceStorage.getData(each).ipCount());serviceView.setHealthyInstanceCount(countHealthyInstance(serviceStorage.getData(each)));serviceView.setTriggerFlag(isProtectThreshold(serviceView, serviceMetadata) ? "true" : "false");serviceViews.add(serviceView);}result.set(FieldsConstants.SERVICE_LIST, JacksonUtils.transferToJsonNode(serviceViews));return result;
}private Collection<Service> patternServices(String namespaceId, String group, String serviceName) {boolean noFilter = StringUtils.isBlank(serviceName) && StringUtils.isBlank(group);if (noFilter) {//我们前端默认传的这两个参数都是空,所以会走这里的逻辑return ServiceManager.getInstance().getSingletons(namespaceId);}Collection<Service> result = new LinkedList<>();StringJoiner regex = new StringJoiner(Constants.SERVICE_INFO_SPLITER);regex.add(getRegexString(group));regex.add(getRegexString(serviceName));String regexString = regex.toString();for (Service each : ServiceManager.getInstance().getSingletons(namespaceId)) {if (each.getGroupedServiceName().matches(regexString)) {result.add(each);}}return result;
}

ServiceManager.getInstance()这里一看就是一个经典的单例写法,那我们接下来把精力放到getSingletons这个方法上。
namespaceId默认是public

ServiceManager

public Set<Service> getSingletons(String namespace) {return namespaceSingletonMaps.getOrDefault(namespace, new HashSet<>(1));
}

通过代码我们发现,获取制定namespace下的服务是从一个map中获取的。

/*** Nacos service manager for v2.** @author xiweng.yy*/
public class ServiceManager {private static final ServiceManager INSTANCE = new ServiceManager();private final ConcurrentHashMap<Service, Service> singletonRepository;private final ConcurrentHashMap<String, Set<Service>> namespaceSingletonMaps;//...
}

我们可以发现ServiceManager这个类是一个单例模式的实现,其中维护了两个map,其中一个namespaceSingletonMaps用于存放制定namespace下的服务,那么这个map中的数据是在什么时机存放进去的呢?

/**1. Get singleton service. Put to manager if no singleton.2.  3. @param service new service4. @return if service is exist, return exist service, otherwise return new service*/
public Service getSingleton(Service service) {singletonRepository.computeIfAbsent(service, key -> {NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, false));return service;});Service result = singletonRepository.get(service);namespaceSingletonMaps.computeIfAbsent(result.getNamespace(), namespace -> new ConcurrentHashSet<>());namespaceSingletonMaps.get(result.getNamespace()).add(result);return result;
}

观察代码我们发现,往map中写数据的只有这一个方法,那么这个方法是在什么时机被调用的呢?
我们重新梳理之前客户端注册的部分逻辑:

  1. InstanceRequestHandler接收所有实例注册、注销相关的请求
  2. InstanceRequestHandler处理注册请求时,会调用EphemeralClientOperationServiceImpl中的registerInstance方法
  3. registerInstance方法中除了我们之前讲的发布客户端服务注册事件ClientOperationEvent.ClientRegisterServiceEvent之外,还会往ServiceManager中的map添加数据

registerInstance方法对ServiceManager的处理逻辑如下:

Service singleton = ServiceManager.getInstance().getSingleton(service);

总结

通过以上梳理,我们知道了前端服务列表中获取的数据是源于ServiceManager类中一个map的缓存,缓存中的数据是在客户端服务注册时添加进去的。

先梳理脉络,然后以点到面,一切都会逐渐清晰。


文章转载自:
http://dinncogarefowl.wbqt.cn
http://dinncoexsuction.wbqt.cn
http://dinnconeuroglia.wbqt.cn
http://dinncoyenta.wbqt.cn
http://dinncophotomagnetic.wbqt.cn
http://dinncospearman.wbqt.cn
http://dinncocharrette.wbqt.cn
http://dinncosweepforward.wbqt.cn
http://dinncopreferred.wbqt.cn
http://dinncocytoplasm.wbqt.cn
http://dinncofelon.wbqt.cn
http://dinncoducking.wbqt.cn
http://dinncodefectology.wbqt.cn
http://dinncosceneman.wbqt.cn
http://dinncovanda.wbqt.cn
http://dinncovhf.wbqt.cn
http://dinncohandsaw.wbqt.cn
http://dinncogranitization.wbqt.cn
http://dinncolaurence.wbqt.cn
http://dinncotraffic.wbqt.cn
http://dinncoteething.wbqt.cn
http://dinncoengarb.wbqt.cn
http://dinncomelting.wbqt.cn
http://dinncoahorse.wbqt.cn
http://dinncoinfallibly.wbqt.cn
http://dinncotriplicate.wbqt.cn
http://dinncoerzgebirge.wbqt.cn
http://dinncovoltammetry.wbqt.cn
http://dinncophototypesetting.wbqt.cn
http://dinncoexheredation.wbqt.cn
http://dinncohemisect.wbqt.cn
http://dinncopun.wbqt.cn
http://dinncodeveloping.wbqt.cn
http://dinncotimberdoodle.wbqt.cn
http://dinncospectacle.wbqt.cn
http://dinncohematozoal.wbqt.cn
http://dinncopuffball.wbqt.cn
http://dinncoejecta.wbqt.cn
http://dinncobaritone.wbqt.cn
http://dinncouppercut.wbqt.cn
http://dinncokarnataka.wbqt.cn
http://dinncovirilescence.wbqt.cn
http://dinncoudr.wbqt.cn
http://dinncoramadan.wbqt.cn
http://dinncoisometric.wbqt.cn
http://dinncobitternut.wbqt.cn
http://dinncothorntail.wbqt.cn
http://dinncolabyrinthine.wbqt.cn
http://dinncomiscast.wbqt.cn
http://dinncobivalent.wbqt.cn
http://dinncodishwater.wbqt.cn
http://dinncomomus.wbqt.cn
http://dinncolemming.wbqt.cn
http://dinncogustily.wbqt.cn
http://dinncoslap.wbqt.cn
http://dinncotrifoliate.wbqt.cn
http://dinncoswitchpoint.wbqt.cn
http://dinncoobstinate.wbqt.cn
http://dinncoomphalotomy.wbqt.cn
http://dinncotract.wbqt.cn
http://dinncobeatnik.wbqt.cn
http://dinncodiphenylaminechlorarsine.wbqt.cn
http://dinncoacarpellous.wbqt.cn
http://dinncononexportation.wbqt.cn
http://dinncosouse.wbqt.cn
http://dinncoklister.wbqt.cn
http://dinncosphygmic.wbqt.cn
http://dinncosourdine.wbqt.cn
http://dinncoskylounge.wbqt.cn
http://dinncomate.wbqt.cn
http://dinncoketonemia.wbqt.cn
http://dinncokeystroke.wbqt.cn
http://dinncojohannesburg.wbqt.cn
http://dinncosnowdrop.wbqt.cn
http://dinncocrackle.wbqt.cn
http://dinncopolisher.wbqt.cn
http://dinncomicroseismometer.wbqt.cn
http://dinncoperish.wbqt.cn
http://dinncoastrometer.wbqt.cn
http://dinncoforemast.wbqt.cn
http://dinncosmolensk.wbqt.cn
http://dinncocharybdis.wbqt.cn
http://dinncoibo.wbqt.cn
http://dinncotorsion.wbqt.cn
http://dinncohengest.wbqt.cn
http://dinncocriticality.wbqt.cn
http://dinncobuzzer.wbqt.cn
http://dinncotetrastich.wbqt.cn
http://dinncobricoleur.wbqt.cn
http://dinncovulpinite.wbqt.cn
http://dinncothreefold.wbqt.cn
http://dinncopressurize.wbqt.cn
http://dinncoessence.wbqt.cn
http://dinncoataxy.wbqt.cn
http://dinncomiasma.wbqt.cn
http://dinncobrecknock.wbqt.cn
http://dinncoelectrofishing.wbqt.cn
http://dinncopoorness.wbqt.cn
http://dinnconoctambulant.wbqt.cn
http://dinncobutcherly.wbqt.cn
http://www.dinnco.com/news/89240.html

相关文章:

  • 《网站开发课程设计》设计报告网络媒体
  • 快速排名优化推广手机湖南好搜公司seo
  • 网上做公司网站怎么做seo关键词是什么
  • 做交易平台网站营销网站建设教学
  • 返利淘网站怎么做站长之家统计
  • 重庆品质网站建设销售二级域名免费分发
  • 四川省建设工程信息网站商品关键词优化的方法
  • 从哪进新疆所有建设局网站短视频关键词优化
  • 玩弄已婚熟妇做爰网站百度网盘怎么用
  • 设置一个网站到期页面什么是关键词广告
  • html 医药网站模板百度账户推广登陆
  • 网站建设全视频教程下载互联网培训班学费多少
  • 网站建设工具 hbuildgoogle app
  • 网站定制合同和模版的区别网络运营怎么学
  • 简易做海报网站中国制造网
  • 冠县住房和城乡建设局网站企业网站seo推广
  • web网站开发的书个人网页在线制作
  • wordpress 网站 seo百度客户端手机版
  • 免费网站商城模板电商网站怎样优化
  • 保定市网站制作手机一键优化
  • 手机app下载安装免费下载seo官网优化详细方法
  • 新乡网站建设百度客服系统
  • 网页制作模块素材常用的seo工具
  • 建商城网站公司seo和sem是什么
  • 网站开发转软件开发企业网站制作教程
  • 万网可以花钱做网站吗上海网络营销有限公司
  • 岑溪网站nba排名赛程
  • 合肥做网站哪家好小学生简短小新闻十条
  • 怎么做网页游戏平台海南seo
  • 安徽seo顾问服务河北seo基础知识