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

建设网站总结报告漳州做网站配博大钱少a

建设网站总结报告,漳州做网站配博大钱少a,android软件开发实例,宜昌本地网站建设2019独角兽企业重金招聘Python工程师标准 一、Ribbon简介 Ribbon是Netflix发布的开源项目#xff0c;主要功能是提供客户端的软件负载均衡算法#xff0c;将Netflix的中间层服务连接在一起。Ribbon客户端组件提供一系列完善的配置项如连接超时#xff0c;重试… 2019独角兽企业重金招聘Python工程师标准 一、Ribbon简介     Ribbon是Netflix发布的开源项目主要功能是提供客户端的软件负载均衡算法将Netflix的中间层服务连接在一起。Ribbon客户端组件提供一系列完善的配置项如连接超时重试等。简单的说就是在配置文件中列出Load Balancer后面所有的机器Ribbon会自动的帮助你基于某种规则如简单轮询随即连接等去连接这些机器。我们也很容易使用Ribbon实现自定义的负载均衡算法。 二、准备工作     这一篇文章基于上一篇文章的工程启动eureka-server 工程启动user-service工程它的端口为8084将user-service的项目复制出来一个将其名称修改为user-service1配置文件的端口改为8085.     启动这时你会发现user-service在eureka-server注册了2个实例这就相当于一个小的集群。访问localhost:1001如图所示 三、建一个服务消费者Ribbon     重新新建一个工程取名为da-ribbon-service;      在它的pom.xml文件分别引入起步依赖spring-boot-starter-web代码如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.example/groupIdartifactIdda-ribbon-server/artifactIdversion0.0.1-SNAPSHOT/versionpackagingjar/packagingnameda-ribbon-server/namedescriptionDemo project for Spring Boot/descriptionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.0.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version1.8/java.versionspring-cloud.versionFinchley.M8/spring-cloud.version/propertiesdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-ribbon/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/buildrepositoriesrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositories/project在工程的配置文件指定服务的注册中心地址为http://localhost:1001/eureka/程序名称为 ribbon-service程序端口为2001。配置文件application.yml如下 eureka:client:serviceUrl:defaultZone: http://localhost:1001/eureka/instance:lease-renewal-interval-in-seconds: 30 server:port: 2001 spring:application:name: ribbon-service     在工程的启动类中,通过EnableEurekaClient向服务中心注册并且向程序的ioc注入一个bean: restTemplate;并通过LoadBalanced注解表明这个restRemplate开启负载均衡的功能。 EnableEurekaClient SpringBootApplication public class DaRibbonServerApplication {public static void main(String[] args) {SpringApplication.run(DaRibbonServerApplication.class, args);}BeanLoadBalancedRestTemplate restTemplate(){return restTemplate();} } 写一个测试类HelloService通过之前注入ioc容器的restTemplate来消费service-hi服务的“/hi”接口在这里我们直接用的程序名替代了具体的url地址在ribbon中它会根据服务名来选择具体的服务实例根据服务实例在请求的时候会用具体的url替换掉服务名代码如下 Service public class HelloService {AutowiredRestTemplate restTemplate;public String getHello(String name){return restTemplate.getForObject(http://user-service/hi?namename,String.class);} } 写一个controller在controller中用调用HelloService 的方法代码如下 RestController public class HiController {AutowiredHelloService helloService;RequestMapping(/hi)public String hi(RequestParam String name){return helloService.getHello(name);} } 在浏览器上多次访问http://localhost:2001/hi?namezhangsan浏览器交替显示 这说明当我们通过调用restTemplate.getForObject(http://user-service/hi?namename,String.class)方法时已经做了负载均衡访问了不同的端口的服务实例。 四、此时的架构 一个服务注册中心eureka-server,端口为1001user-service跑了两个工程实例端口分别为8084,8085分别向服务注册中心注册ribbon-sercvice端口为2001,向服务注册中心注册当ribbon-sercvice通过restTemplate调用user-service的hi接口时因为用ribbon进行了负载均衡会轮流的调用user-service8084和8085 两个端口的hi接口 五、源码下载     RibbonServer源码下载https://gitee.com/Clarences/Ribbon-Service     UserServer1源码下载https://gitee.com/Clarences/User-server1 转载于:https://my.oschina.net/Clarences/blog/1635795
http://www.yutouwan.com/news/240502/

相关文章:

  • 软件公司网站wordpress动态主题
  • 大连建站万网注册域名的步骤
  • 搭建什么网站赚钱北京网站怎么建设
  • 制作卡牌的网站wordpress微拍源码
  • 怎么做自己网站的后台蜜雪冰城网页设计素材
  • 优设设计网站导航天津建设招标网站
  • 个人网站做打赏流程个人网站建立步骤
  • 做网站公司哪家好关于家乡的网页制作教程
  • 哈尔滨网站建设多少钱wordpress导航 t
  • 长沙智能建站方案高端定制网站的特点
  • 商务咨询公司网站制作模板教育网站开发文档
  • 网站安全优化yum wordpress php扩展
  • 做淘宝客网站公司法人查询
  • wordpress 网站搬迁上海定制网站建设公司
  • 重庆有网站公司君通网站怎么样
  • 甘州区建设局网站做网站公司排名电话
  • 做个网站怎么赚钱罗湖、龙华、龙岗最新通告
  • 免费网站模板 带后台wordpress插件直播
  • 梧州网站制作基于html5的电商网站开发
  • 鞋行业的网站建设什么是电商平台推广
  • 诸葛企业网站建设公司树莓派做网站服务器怎样
  • 仿朋友圈网站建设站长统计app进入网址新版小猪
  • 潍坊高端网站开发做网站毕业设计能过吗
  • 联想粒子云可以做网站公司网站被抄袭
  • 网站模板和源码区别福州专业做网站的公司有哪些
  • 做一个官方网站需要多少钱中国新闻发布
  • 做平面有什么好的网站网站网页制作及优化
  • 网站的首页需要什么内容谷歌浏览器引擎入口
  • 在淘宝上做的网站要转出简历制作免费模板网站
  • 永久免费素材网站wordpress加入购买功能