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

东莞定制网站建设淘宝直播要先建设个网站吗

东莞定制网站建设,淘宝直播要先建设个网站吗,深圳互联网公司50强,网上做物理题赚钱的网站转载请标明出处#xff1a; 原文首发于#xff1a;https://www.fangzhipeng.com/springcloud/2018/08/30/sc-f2-ribbon/ 本文出自方志朋的博客 在上一篇文章#xff0c;讲了服务的注册和发现。在微服务架构中#xff0c;业务都会被拆分成一个独立的服务#xff0c;服务与服… 转载请标明出处 原文首发于https://www.fangzhipeng.com/springcloud/2018/08/30/sc-f2-ribbon/ 本文出自方志朋的博客 在上一篇文章讲了服务的注册和发现。在微服务架构中业务都会被拆分成一个独立的服务服务与服务的通讯是基于http restful的。Spring cloud有两种服务调用方式一种是ribbonrestTemplate另一种是feign。在这一篇文章首先讲解下基于ribbonrest。 一、ribbon简介 Ribbon is a client side load balancer which gives you a lot of control over the behaviour of HTTP and TCP clients. Feign already uses Ribbon, so if you are using FeignClient then this section also applies. -----摘自官网 ribbon是一个负载均衡客户端可以很好的控制htt和tcp的一些行为。Feign默认集成了ribbon。 ribbon 已经默认实现了这些配置bean IClientConfig ribbonClientConfig: DefaultClientConfigImpl IRule ribbonRule: ZoneAvoidanceRule IPing ribbonPing: NoOpPing ServerList ribbonServerList: ConfigurationBasedServerList ServerListFilter ribbonServerListFilter: ZonePreferenceServerListFilter ILoadBalancer ribbonLoadBalancer: ZoneAwareLoadBalancer 二、准备工作 这一篇文章基于上一篇文章的工程启动eureka-server 工程启动service-hi工程它的端口为8762将service-hi的配置文件的端口改为8763,并启动这时你会发现service-hi在eureka-server注册了2个实例这就相当于一个小的集群。 如何在idea下启动多个实例请参照这篇文章https://blog.csdn.net/forezp/article/details/76408139 访问localhost:8761如图所示 如何一个工程启动多个实例请看这篇文章:https://blog.csdn.net/forezp/article/details/76408139 三、建一个服务消费者 重新新建一个spring-boot工程取名为service-ribbon; 在它的pom.xml继承了父pom文件并引入了以下依赖 ?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.forezp/groupIdartifactIdservice-ribbon/artifactIdversion0.0.1-SNAPSHOT/versionpackagingjar/packagingnameservice-ribbon/namedescriptionDemo project for Spring Boot/descriptionparentgroupIdcom.forezp/groupIdartifactIdsc-f-chapter2/artifactIdversion0.0.1-SNAPSHOT/version/parentdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-ribbon/artifactId/dependency/dependencies/project 在工程的配置文件指定服务的注册中心地址为http://localhost:8761/eureka/程序名称为 service-ribbon程序端口为8764。配置文件application.yml如下 eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/ server:port: 8764 spring:application:name: service-ribbon在工程的启动类中,通过EnableDiscoveryClient向服务中心注册并且向程序的ioc注入一个bean: restTemplate;并通过LoadBalanced注解表明这个restRemplate开启负载均衡的功能。 SpringBootApplication EnableEurekaClient EnableDiscoveryClient public class ServiceRibbonApplication {public static void main(String[] args) {SpringApplication.run( ServiceRibbonApplication.class, args );}BeanLoadBalancedRestTemplate restTemplate() {return new RestTemplate();}} 写一个测试类HelloService通过之前注入ioc容器的restTemplate来消费service-hi服务的“/hi”接口在这里我们直接用的程序名替代了具体的url地址在ribbon中它会根据服务名来选择具体的服务实例根据服务实例在请求的时候会用具体的url替换掉服务名代码如下 Service public class HelloService {AutowiredRestTemplate restTemplate;public String hiService(String name) {return restTemplate.getForObject(http://SERVICE-HI/hi?namename,String.class);}} 写一个controller在controller中用调用HelloService 的方法代码如下 RestController public class HelloControler {AutowiredHelloService helloService;GetMapping(value /hi)public String hi(RequestParam String name) {return helloService.hiService( name );} } 在浏览器上多次访问http://localhost:8764/hi?nameforezp浏览器交替显示 hi forezp,i am from port:8762 hi forezp,i am from port:8763 这说明当我们通过调用restTemplate.getForObject(“http://SERVICE-HI/hi?name”name,String.class)方法时已经做了负载均衡访问了不同的端口的服务实例。 四、此时的架构 一个服务注册中心eureka server,端口为8761service-hi工程跑了两个实例端口分别为8762,8763分别向服务注册中心注册sercvice-ribbon端口为8764,向服务注册中心注册当sercvice-ribbon通过restTemplate调用service-hi的hi接口时因为用ribbon进行了负载均衡会轮流的调用service-hi8762和8763 两个端口的hi接口源码下载https://github.com/forezp/SpringCloudLearning/tree/master/sc-f-chapter2 五、参考资料 本文参考了以下 http://blog.csdn.net/forezp/article/details/69788938 http://cloud.spring.io/spring-cloud-static/Finchley.RELEASE/single/spring-cloud.html 扫码关注公众号有惊喜 转载本站文章请注明作者和出处 方志朋的博客 转载于:https://www.cnblogs.com/forezp/p/9852086.html
http://www.zqtcl.cn/news/67663/

相关文章:

  • 哈尔滨建站系统报价北京大型商场
  • 重庆信息发布平台外贸网站优化公司
  • 网站开发需要几个人一般的域名可以做彩票网站吗
  • 北京市建设网站构建新发展格局
  • 广州网站建设88广州网站推广策划案
  • 企业管理研究生学校排名seo品牌优化
  • 电脑禁止访问网站设置网页设计与网站建设的报告
  • 郑州网站建设兄长好wordpress汉化软件
  • 网站显示内容不显示亚星网站代理
  • 网站建设定做公司网站建设一般多少钱
  • 公司门户网站建设公司会写网站怎么赚钱
  • 做网站要什么知识条件网设
  • 湖南网站优化公司湖南省建设人力资源网站
  • 福田附近网站建设wordpress忘了后台密码怎么办
  • 北京网站建设曝光尚词网wordpress商
  • 怎么发布php网站做的网站怎样适配手机屏幕
  • 保定手机网站建设人力资源管理咨询公司
  • 先进网站建设有哪些wordpress评论显示数字ip
  • 效果好的郑州网站建设哪家能建设网站
  • 简约网站模板什么是网络营销中最容易出现问题的步骤
  • 网站开发环境windows7的优点网站如何投放广告
  • 山东网站制作团队新闻联播俄罗斯与乌克兰
  • 网站名字大全电商网站建设服务平台
  • 中职网站建设与管理专业网站请人做的 域名自己注册的 知道网站后台 怎么挂自己的服务器
  • 网页设计网站搭建黑马程序员广州校区
  • 专业做私募网站低成本做网站
  • 网站建设和网站设计一样吗wordpress建站论坛
  • php是做网站美工的吗wordpress 下载页面
  • 杭州企业网站制作公司手机网站营销
  • 企业网站建设的经费预算幼儿做爰网站