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

建设工程交易中心网站收费标准wordpress 首页打不开

建设工程交易中心网站收费标准,wordpress 首页打不开,有口碑的唐山网站建设,仙桃做网站的公司有哪些目录 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.yayakq.cn/news/985929/

相关文章:

  • 网站设计现状微信电脑版
  • 网站改版对seo物联网工程专业好就业吗
  • 济南企业网站设计网页开发者模式
  • 昆明网站快照优化公司微网站教程
  • 在网上建设网站合作加盟
  • 门户网站的区别中国万网域名注册免费
  • 抖音网站开发重庆网站优化排名
  • 小米商城网站建设医馆网站建设方案
  • 怎么做品牌推广网站怎样汉化wordpress主题
  • 禅城技术支持骏域网站建设专门做养老院的网站
  • 网站开发维护的工作职责ps做特效哪个网站好
  • 做家教网站怎么样十大高端网站建设
  • 网站短期电脑培训班学费wordpress交易平台主题
  • 做网站需要招聘内容范本网站开发流程龙岩
  • 2000个免费货源网站关键词排名方案
  • 网站空间免费吗哪个网站教做公众号
  • 最新网站开发语言可以用来做简单的网络验证的网站
  • 四川定制网站建设国际网站后缀
  • 网站都是每年续费的吗深圳网站设计 深圳市利
  • 展示型网站企业网站建设广州安全教育平台软件
  • 天津公司网站如何制作有网站源代码能自己做网站吗
  • 网站建设是怎么挣钱的东莞有哪些做网站
  • 河北网站建设哪里好centos一键wordpress
  • 做 58 那样的网站北京做企业网站
  • 高端的环保行业网站开发泊头市网站建设价格
  • 情侣博客网站模板建立内部网站
  • 建设信用卡积分商城网站德城区建设局网站
  • 多用户自助建站系统长春网站推广优化公司哪家好
  • 萧云建设网站淘宝网站小视频怎么做的
  • 不拦截网站的浏览器合同管理软件