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

html网站开发相关书籍百度seo快速排名优化服务

html网站开发相关书籍,百度seo快速排名优化服务,越南做企业网站,残疾人无障碍网站怎么做目录 1.什么是Ribbo❤️❤️❤️ 2.eureka自带Ribbon ❤️❤️❤️ 3. RestTemplate❤️❤️❤️ 4.IRule❤️❤️❤️ 5.负载均衡算法❤️❤️❤️ 1.什么是Ribbo 1.Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端,负载均衡的工具。2.主要功能是提供客户端的软件…

目录

1.什么是Ribbo❤️❤️❤️

2.eureka自带Ribbon ❤️❤️❤️

3. RestTemplate❤️❤️❤️

 4.IRule❤️❤️❤️

 5.负载均衡算法❤️❤️❤️


1.什么是Ribbo

  • 1.Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端,负载均衡的工具。
  • 2.主要功能是提供客户端的软件负载均衡算法和服务调用
  • 3.Ribbon客户端组件提供一系列完善的配置项如连接超时,重试等。
  • 4.在配置文件中列出Load Balancer (简称LB)后面所有的机器,Ribbon会自动的帮助你基于某种规则(如简单轮询,随机连接等)去连接这些机器。

2.eureka自带Ribbon 

之前没引入Ribbon为啥也能负载均衡?

因为我们引入eureka时,eureka自动引入了ribbon

3. RestTemplate

restTemplate有两种方式:

  • 1.restTempalte.getForObject
  • 2.restTemplate.getForEntity
  @GetMapping("/payment/get/{id}")public CommonResult<Payment> getPayment(@PathVariable("id") Integer id) {log.info("进入查询功能成功");return restTemplate.getForObject(PAYMENT_URL + "/payment/selectById/" + id, CommonResult.class);}@GetMapping("/payment/get2/{id}")public CommonResult<Payment> getPayment2(@PathVariable("id") Integer id) {log.info("进入查询功能成功");ResponseEntity<CommonResult> entity = restTemplate.getForEntity(PAYMENT_URL + "/payment/selectById/" + id, CommonResult.class);if (entity.getStatusCode().is2xxSuccessful()){log.info(entity.getStatusCode()+"\t"+entity.getHeaders());return entity.getBody();}else {return new CommonResult<>(404,"查询失败~");}}

 4.IRule

4.1轮询策略

  • 1.RoundRobinRule      --------轮询
  • 2.RandomRule            ---------随机
  • 3.RetryRule                 ---------重试  (先轮询,如果失败,在执行时间内重试

4.2如何替换 

1.创建配置类

注意:创建的配置类,不能被@ComponentSacn所扫描(不能与主启动类同包)

2.创建IRule对象 

使用@Bean创建对象,根据要求返回具体实现类

@Configuration
public class MySelfRule {@Beanpublic IRule myRule(){return new RandomRule();//定义为随机}
}

 3.添加@RibbonClient

name属性:表示要访问服务的名称。(必须与Eureka中的名称一致,包括大小写

configuration属性:表示要访问的自定义IRUle配置类

@SpringBootApplication
@EnableDiscoveryClient
@RibbonClient(name = "COULD-PAYMENT-SERVICE",configuration = MySelfRule.class)
public class OrderMain80 {public static void main(String[] args) {SpringApplication.run(OrderMain80.class);}
}

 5.负载均衡算法

5.1原理

  • 算法:rest接口第几次请求数 % 服务器集群总数量 = 实际调用服务器位置下标,每次服务重启动后rest接口计数从1开始。 

例如:

List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");

获取实例:

List [0] instances = 127.0.0.1:8002

List [1] instances = 127.0.0.1:8001

8001和8002组成集群,共两台机器:

当总请求数为1时: 1%2=1对应下标位置为1 ,则获得服务地址为127.0.0.1:8001

当总请求数位2时: 2%2=0对应下标位置为0,则获得服务地址为127.0.0.1:8002

当总请求数位3时: 3%2=1对应下标位置为1 ,则获得服务地址为127.0.0.1:8001

当总请求数位4时: 4%2=0对应下标位置为0,则获得服务地址为127.0.0.1:8002

 5.2手写轮询

  • 自定义轮询算法
@Component
public class MyLb implements LoadBalance {private AtomicInteger atomicInteger = new AtomicInteger(0);public final int getAndIncrement() {int current;int next;do {current = this.atomicInteger.get();next = current >= Integer.MAX_VALUE ? 0 : current + 1;} while (!this.atomicInteger.compareAndSet(current, next));System.out.println("next:" + next);return next;}@Overridepublic ServiceInstance instances(List<ServiceInstance> serviceInstance) {int index = getAndIncrement() % serviceInstance.size();return serviceInstance.get(index);}
}
  • 80服务使用自定义轮询
    //自己的负载均衡算法@Autowiredprivate LoadBalance loadBalance;@Autowiredprivate DiscoveryClient discoveryClient;@GetMapping("/payment/lb")public String getPaymentLb() {List<ServiceInstance> instances = discoveryClient.getInstances("COULD-PAYMENT-SERVICE");if (instances == null || instances.size() < 0) {return null;}ServiceInstance serviceInstance=loadBalance.instances(instances);URI uri = serviceInstance.getUri();return restTemplate.getForObject(uri+"/payment/lb",String.class);}

http://www.hkea.cn/news/961331/

相关文章:

  • 广告免费设计在线生成网站排名优化
  • 余姚公司网站建设怎么建网址
  • 网站域名授权怎么做市场营销案例100例
  • kindeditor代码高亮 wordpressseo优化排名经验
  • 家乡介绍网页设计上海网站排名优化
  • 广州黄埔网站制作百度sem是什么意思
  • 网站流量分析网站网络推广营销网
  • 化妆品网站建设计划书网站维护是什么意思
  • 建设局网站公告宣传推广的形式有哪些
  • 网站基本架构设计的主要步骤什么软件可以排名次
  • 代做毕业设计网站多少钱网站推广交换链接
  • 苹果指争议广告lg广告北京seo公司网站
  • flash网站制作公司能打开各种网站的浏览器下载
  • 网站开发是叫系统吗站长工具seo排名查询
  • 站长之家html模板西安网站seo技术厂家
  • 重庆网站建设 渝seo交流论坛
  • 洛阳市网站建设宁波seo网络推广软件系统
  • 做网站用建站模版好还是定制好百度站点
  • 关注济南网站建设深圳市企业网站seo
  • 安溪县住房和城乡建设网站色盲
  • 合肥做英文网站今日头条国际军事新闻
  • 西安有哪些做网站的公司好邵阳疫情最新消息
  • asia域名的网站竞价广告
  • 怎么注册公司支付宝账号seo求职信息
  • 多语言网站怎么做网络推广平台公司
  • 山东公司注册网站怎样写营销策划方案
  • 河北省香河县建设局网站中国互联网协会
  • 北京丰台区网站建设游戏推广赚佣金的平台
  • 网站没排名怎么办搜索引擎广告优化
  • wordpress内容主题模板网络网站推广选择乐云seo