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

网站开发自适应不同分辨率网站出现转站怎么办

网站开发自适应不同分辨率,网站出现转站怎么办,企业网站策划书1000字,免费网站建站下载在上一篇文章#xff0c;讲了服务的注册和发现。在微服务架构中#xff0c;业务都会被拆分成一个独立的服务#xff0c;服务与服务的通讯是基于http restful的。Spring cloud有两种服务调用方式#xff0c;一种是ribbonrestTemplate#xff0c;另一种是feign。在这一篇文章…在上一篇文章讲了服务的注册和发现。在微服务架构中业务都会被拆分成一个独立的服务服务与服务的通讯是基于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是一个负载均衡客户端可以很好的控制http和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 工程启动sale-service工程它的端口为8762将sale-service的代码复制一份工程取名为sale-service2的配置文件的端口改为8763,并启动 这时你会发现sale-service在eureka-server注册了2个实例这就相当于一个小的集群。访问localhost:8761如图所示 如何一个工程启动多个实例请自行搜资料解决。 三、建一个服务消费者 重新新建一个spring-boot工程取名为service-ribbon; 在它的pom.xml文件分别引入起步依赖spring-cloud-starter-eureka、spring-cloud-starter-ribbon、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.hmblogs/groupIdartifactIdservice-ribbon/artifactIdversion0.0.1-SNAPSHOT/versionpackagingjar/packagingnameservice-ribbon/namedescriptionDemo project for Spring Boot/descriptionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion1.5.2.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-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/artifactIdversionDalston.RC1/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: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开启负载均衡的功能。 package com.hmblogs;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate;SpringBootApplication EnableDiscoveryClient public class ServiceRibbonApplication {public static void main(String[] args) {SpringApplication.run(ServiceRibbonApplication.class, args);}BeanLoadBalancedRestTemplate restTemplate() {return new RestTemplate();}}写一个测试类HelloService通过之前注入ioc容器的restTemplate来消费sale-service服务的“/hi”接口在这里我们直接用的程序名替代了具体的url地址在ribbon中它会根据服务名来选择具体的服务实例根据服务实例在请求的时候会用具体的url替换掉服务名代码如下 package com.hmblogs;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate;Service public class HelloService {AutowiredRestTemplate restTemplate;public String hiService(String name) {return restTemplate.getForObject(http://sale-service/hi?namename,String.class);}}写一个controller在controller中调用HelloService 的方法代码如下 package com.hmblogs;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;RestController public class HelloControler {AutowiredHelloService helloService;RequestMapping(value /invokeHi)public String hi(RequestParam String name){return helloService.hiService(name);}}在浏览器上多次访问http://localhost:8764/invokeHi?nameforezp浏览器交替显示 hi forezp,i am from port:8762 hi forezp,i am from port:8763 这说明当我们通过调用restTemplate.getForObject(“http://sale-service/hi?name”name,String.class)方法时已经做了负载均衡访问了不同的端口的服务实例。 代码结构如下图 ​​​​​​​ 四、此时的架构 一个服务注册中心eureka server,端口为8761 sale-service工程跑了两个实例端口分别为8762,8763分别向服务注册中心注册 sercvice-ribbon端口为8764,向服务注册中心注册 当sercvice-ribbon通过restTemplate调用sale-service的hi接口时因为用ribbon进行了负载均衡会轮流的调用sale-service8762和8763 两个端口的hi接口
http://www.dnsts.com.cn/news/177431.html

相关文章:

  • 电子政务门户网站建设山西两学一做网站登录
  • 网站内容搜索python 网站开发入门
  • 专门做恐怖片的网站广东省路桥建设发展有限公司网站
  • 域名费用和网站服务器费用是同样的吗工业产品设计包括哪些
  • 建设网站得多少钱上海怎样建设网站
  • 怎么用jsp做网站WordPress生成海报插件
  • 天津移动网站建设网站平台怎么做推广
  • 做网站 英语wordpress page 自定义
  • 小网站建设聊城的网站制作公司
  • 兰州做网站改版的公司免费wap建站
  • 深圳网站设计 建设首选深圳市做怎样的网站能赚钱
  • 个人电脑做服务器映射网站潍坊做网站软件
  • 提供网站建设设计外包手工制作粽子
  • 宁波关键词网站排名如何利用网络进行推广和宣传
  • 重庆怎么做网站?wordpress如何添加首页
  • 涨口碑说做的网站餐饮logo设计
  • 免费网站模板素材电子商务营销渠道
  • 做电影分享网站违法吗wordpress用户投稿插件
  • 怎么制作手机网站网站建设员是做什么的
  • 建外贸网站需要多少钱企业管理咨询有限公司的经营范围
  • 网站建设公司好吗建设网站的功能及目的是什么
  • 深圳网站的网络公司西安网站制作公司官网
  • 成都手机网站建设标识设计师
  • 南昌市网站备案义乌广告设计与制作
  • 教务系统门户网站网站引导页怎么做.
  • 英文网站搜索广州近期流行的传染病
  • 网站中的ppt链接怎么做的简历设计网站
  • 温州建站平台视频转链接在线生成
  • 建设专业网站排名智慧软文发稿平台
  • 外贸网站模板免费下载定制一款软件需要多少钱