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

网站建设服务ysaigo企业网站管理系统最新4湖南岚鸿牛x1 0

网站建设服务ysaigo,企业网站管理系统最新4湖南岚鸿牛x1 0,网站做伪原创收录,开o2o网站需要什么手续1.springcloud微服务架构搭建 之 《springboot自动装配Redis》 2.springcloud微服务架构搭建 之 《springboot集成nacos注册中心》 ribbon工作原理自己网上百度#xff0c;说的都很详细 目录 1.项目引入openfeign和ribbon配置 2.新建lilock-ribbon-spring-boot-starter 3…1.springcloud微服务架构搭建 之 《springboot自动装配Redis》 2.springcloud微服务架构搭建 之 《springboot集成nacos注册中心》 ribbon工作原理自己网上百度说的都很详细 目录 1.项目引入openfeign和ribbon配置 2.新建lilock-ribbon-spring-boot-starter 3.增加restTemplate配置类 4.配置Ribbon配置类 5.配置ribbon自动装配spring.factories 6.新建一个cms业务服务开始测试 7.配置ribbon参数 8.新建测试类进行测试 9.在user服务调用 1.项目引入openfeign和ribbon配置 openfeign集成了ribbon需要单独给ribbon配置参数信息 !-- openfeign 集成了ribbonopenfeign坐标引入 版本号2.1.3.RELEASE-- dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactIdversion${spring.cloud.version}/version /dependency dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-ribbon/artifactIdversion${spring.cloud.version}/version /dependency!--配置httpclient 版本号4.5.9-- dependencygroupIdorg.apache.httpcomponents/groupIdartifactIdhttpclient/artifactIdversion${httpclient.version}/version /dependency 2.新建lilock-ribbon-spring-boot-starter 引入ribbon坐标 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdlilock-commons/artifactIdgroupIdlilock.cn/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionversion1.0-SNAPSHOT/versionartifactIdlilock-feign-spring-boot-starter/artifactIddependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-ribbon/artifactId/dependencydependencygroupIdorg.apache.httpcomponents/groupIdartifactIdhttpclient/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency/dependencies/project 3.增加restTemplate配置类 package lilock.cn.common.ribbon.properties;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefix lilock.rest-template) Data public class RestTemplateProperties {/*** 最大链接数*/private int maxTotal 300;/*** 同路由最大并发数*/private int maxPerRoute 200;/*** 读取超时时间 ms*/private int readTimeout 30000;/*** 链接超时时间 ms*/private int connectTimeout 15000;/**** 最大重试次数*/private int maxAutoRetries 0;/*** 是否支持重试*/private boolean enableRetry false; }4.配置Ribbon配置类 package lilock.cn.common.ribbon.config;import com.netflix.loadbalancer.IRule; import com.netflix.loadbalancer.RoundRobinRule; import lilock.cn.common.ribbon.properties.RestTemplateProperties; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate;EnableConfigurationProperties public class RibbonConfig {Autowiredprivate RestTemplateProperties restTemplateProperties;BeanLoadBalancedpublic RestTemplate restTemplate(ClientHttpRequestFactory factory){RestTemplate restTemplate new RestTemplate();//设置resttemplate http工厂restTemplate.setRequestFactory(factory);return restTemplate;}/*** 配置默认负载均衡策略-轮训* return*/BeanPrimarypublic IRule ribbonRule(){IRule rule new RoundRobinRule();return rule;}BeanPrimarypublic ClientHttpRequestFactory httpRequestFactory(HttpClient httpclient){//设置httpclientreturn new HttpComponentsClientHttpRequestFactory(httpclient);}/*** 配置httpclient 参数* return*/Beanpublic HttpClient httpClient(){RegistryConnectionSocketFactory registry RegistryBuilder.ConnectionSocketFactorycreate().register(http, PlainConnectionSocketFactory.getSocketFactory()).register(https, SSLConnectionSocketFactory.getSocketFactory()).build();PoolingHttpClientConnectionManager connectionManager new PoolingHttpClientConnectionManager(registry);// 最大链接数connectionManager.setMaxTotal(restTemplateProperties.getMaxTotal());// 同路由并发数20connectionManager.setDefaultMaxPerRoute(restTemplateProperties.getMaxPerRoute());RequestConfig requestConfig RequestConfig.custom()// 读超时.setSocketTimeout(restTemplateProperties.getReadTimeout())// 链接超时.setConnectTimeout(restTemplateProperties.getConnectTimeout())// 链接不够用的等待时间.setConnectionRequestTimeout(restTemplateProperties.getReadTimeout()).build();return HttpClients.custom().setDefaultRequestConfig(requestConfig).setConnectionManager(connectionManager).setRetryHandler(new DefaultHttpRequestRetryHandler(restTemplateProperties.getMaxAutoRetries(),restTemplateProperties.isEnableRetry())).build();} }5.配置ribbon自动装配spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration \ lilock.cn.common.ribbon.properties.RestTemplateProperties,\ lilock.cn.common.ribbon.config.RibbonConfig 6.新建一个cms业务服务开始测试 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdlilock-modules/artifactIdgroupIdlilock.cn/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionversion1.0-SNAPSHOT/versionartifactIdlilock-service-cms/artifactIddependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactId/dependencydependencygroupIdlilock.cn/groupIdartifactIdlilock-feign-spring-boot-starter/artifactIdversion${project.version}/version/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactId/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactId/dependencydependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build /project 7.配置ribbon参数 server.port 可以配置不同的端口cms服务启动2次模拟负载我这里端口分别配置的是8990,8991 lilock:rest-template:max-total: 300 #最大连接数max-per-route: 200 #路由最大数max-auto-retries: 0 #最大重试次数enable-retry: false #是否开启重试connect-timeout: 15000 #链接超时时间read-timeout: 30000 #请求超时时间 spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848register-enabled: truenamespace: devapplication:name: lilock-service-cms server:port: 89908.新建测试类进行测试 package lilock.cn.cms.controller;import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController RequestMapping(/api/cms) Api(value cms接口管理,tags {CMS接口管理}) Slf4j public class CmsController {Value(${server.port})private Integer port;Value(${spring.application.name})private String service;GetMapping(/hello)public String getHello(){return [ service ]点前服务端口号是:[ port ]返回内容 HELLO ;} }9.在user服务调用 package lilock.cn.user.controller;import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate;RestController RequestMapping(path /user) Api(value 系统用户,tags {系统用户}) Slf4j public class UserController {Autowiredprivate RestTemplate restTemplate;GetMapping(/testTemplate)public String testTemplate(){String value restTemplate.getForObject(http://lilock-service-cms/api/cms/hello,String.class);log.info(获取当前请求结果:{},value);return value;} }可以看到8990,8991 2个端口对应的服务轮训返回说明配置的轮训策略生效
http://www.hkea.cn/news/14535958/

相关文章:

  • jsp网站连接数据库wordpress大学主题安装
  • 自己可以免费做网站吗不做网站做百家号
  • 做网站游戏推广赚钱吗农业网站设计
  • 织梦网站修改首页图片谷歌seo和百度seo区别
  • 网站开发工作总结论文app注册推广任务平台
  • 上海网站建设建站织梦网站站标
  • 威海营销型网站建设陕西住房城乡建设厅网站
  • 在百度上建网站做网站配置服务器
  • 上海网站推广很好上海电信网站备案
  • 动漫网站建设前期策划成都网站开发公司哪家好
  • 网站模板套餐做网站本溪
  • 成都网站推广公司小羚羊网站怎么建设
  • 中山蓝图科技网站建设芜湖做网站建设公司
  • 网站建设 招聘粤健康app下载
  • 长春企业网站设计贵州百度竞价网页设计
  • asp网站图片万网做网站给网站源码
  • 公司付网站会员费科目怎么做私募基金网站建设要求
  • 银川网站建设效果最新做做网站
  • 外贸网站建设 佛山做片头 网站
  • 网站怎么做外链接地址自己制作游戏的软件
  • jsp网站开发工资域名访问网站下
  • 在哪可以建一个网站网站建设感悟
  • 个人备案网站可以做商城展示开发公司网站
  • 电子商务网站建设与管理笔试设计公司介绍模板
  • 湘icp备 网站建设 农业 湖南wordpress邮箱验证失败
  • 为什么百度没有收录我的网站完全免费建站系统
  • 网站模板设计德语网站域名
  • 重庆点优建设网站公司南通网站建设推广
  • 电子商务网站设计与建设外贸公司推广方案
  • 聊天室网站开发如何做电商新手入门