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

设计案例展示网站好看的个人工作室源码

设计案例展示网站,好看的个人工作室源码,齐鲁人才网最新招聘网,学校网站建设主体前文地址: 001 SpringCloudAlibaba整合 - Nacos注册配置中心、Sentinel流控、Zipkin链路追踪、Admin监控 文章目录 8.Feign远程调用、loadbalancer负载均衡整合1.OpenFeign整合1.引入依赖2.启动类添加EnableFeignClients注解3.yml配置4.日志配置5.远程调用测试6.服务…

前文地址:
001 SpringCloudAlibaba整合 - Nacos注册配置中心、Sentinel流控、Zipkin链路追踪、Admin监控

文章目录

    • 8.Feign远程调用、loadbalancer负载均衡整合
      • 1.OpenFeign整合
        • 1.引入依赖
        • 2.启动类添加`@EnableFeignClients`注解
        • 3.yml配置
        • 4.日志配置
        • 5.远程调用测试
        • 6.服务降级
        • 7.重试配置,服务端异常捕获
        • 8.连接池配置
      • 2.Loadbalancer负载均衡测试
        • 1.复制客户端
        • 2.修改端口启动
        • 3.测试
        • 4.修改负载均衡算法

8.Feign远程调用、loadbalancer负载均衡整合

1.OpenFeign整合

1.引入依赖

注意:由于openfeign高版本使用loadbalancer负载均衡而不是ribbon,所以需要引入loadbalancer依赖排除ribbon,否则会报错

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
        <dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><exclusions><exclusion><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId></exclusion></exclusions></dependency>
2.启动类添加@EnableFeignClients注解
3.yml配置
#由于feign高版本使用loadbalancer负载均衡,排除了ribbon,所以超时时间不能使用ribbon配置
feign:#开启feign对sentinel支持sentinel:enabled: true#feign gzip压缩配置compression:request:enabled: true# 配置压缩的类型mime-types: text/xml,application/xml,application/json# 最小压缩值min-request-size: 2048response:enabled: trueclient:config:#服务名称cloud-production:# 连接超时时间connectTimeout: 90000# 请求处理超时时间readTimeout: 90000# default 全局配置,可以用服务名配置单个服务default:#日志级别,BASIC就是最基本的请求和响应信息loggerLevel: BASIC

springboot全局压缩配置

server:# gzip压缩配置compression:min-response-size: 512mime-types: application/json,application/xml,text/html,text/xml,text/plainexcluded-user-agents: gozilla,traviataenabled: true
4.日志配置

方式一

#日志收集
logging:#feign日志配置level:com.moshangshang.cloud.clean.feign.ProductionFeign: debug  #扫描的是你那个service的类全类名,也可扫包

方式二

feign:client:config:default:#日志级别,BASIC就是最基本的请求和响应信息loggerLevel: BASIC

方式三

@Configuration
public class FeignConfig {/*** feign日志配置*/@Beanpublic Logger.Level feignLogLevel(){return Logger.Level.BASIC; // 日志级别为BASIC}}

单个远程调用使用

@FeignClient(value = "cloud-production",configuration = FeignConfig.class)

全局使用

@EnableFeignClients(defaultConfiguration = FeignConfig.class)
5.远程调用测试

1.fegin调用接口

@FeignClient(value = "cloud-production",configuration = FeignConfig.class)
public interface ProductionFeign {@GetMapping("/cloud-production/test1")String test1();}

2.调用方法

@RestController
@RequestMapping("/cloud-clean")
public class CleanController {@Autowiredprivate ProductionFeign productionFeign;@GetMapping("/test1")public void test1(){String s = productionFeign.test1();System.out.println("远程调用接收到的数据"+s);}}

3.被调用服务方法

@RestController
@RequestMapping("/cloud-production")
public class ProductionController {@GetMapping("/test1")public String test1(){System.out.println("test1 被调用了");return "111";}}

4.测试结果

6.服务降级

1.编写降级工厂类

/*** 服务降级*/
@Slf4j
@Component
public class ProductionFallbackFactory implements FallbackFactory<ProductionFeign> {@Overridepublic ProductionFeign create(Throwable cause) {log.error("服务异常。。。。。。。。。。。。。。。。。。。" + cause);return new ProductionFeign() {@Overridepublic String test1() {return "Fallback回滚";}};}
}

2.使用

@FeignClient(value = "cloud-production",fallbackFactory = ProductionFallbackFactory.class)
7.重试配置,服务端异常捕获
@Slf4j
@Configuration
public class FeignConfiguration {/*** 自定义重试机制*/@Beanpublic Retryer feignRetryer() {//最大请求次数为5,初始间隔时间为100ms,下次间隔时间1.5倍递增,重试间最大间隔时间为1s,return new Retryer.Default();}/*** 客户端捕获服务端异常*/@Beanpublic ErrorDecoder feignError() {return (key, response) -> {if (response.status() == 400) {log.error("请求xxx服务400参数错误,返回:{}", response.body());}if (response.status() == 409) {log.error("请求xxx服务409异常,返回:{}", response.body());}if (response.status() == 404) {log.error("请求xxx服务404异常,返回:{}", response.body());}// 其他异常交给Default去解码处理// 这里使用单例即可,Default不用每次都去newreturn new ErrorDecoder.Default().decode(key, response);};}}
@FeignClient(value = "cloud-production",fallbackFactory = ProductionFallbackFactory.class,configuration = MyConfiguration.class)

8.连接池配置
<!--使用连接池--><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId></dependency>
feign:httpclient:# 支持httpClient的开关enabled: true#最大连接数max-connections: 200# 单个路径的最大连接数max-connections-per-route: 50

2.Loadbalancer负载均衡测试

1.复制客户端

2.修改端口启动

3.测试

默认轮询方式调用

4.修改负载均衡算法

1.创建核心配置类

@Configuration
public class RestTemplateConfig {@Bean@LoadBalancedpublic RestTemplate restTemplate() {return new RestTemplate();}@BeanReactorLoadBalancer<ServiceInstance> randomLoadBalancer(Environment environment,LoadBalancerClientFactory loadBalancerClientFactory) {// 获取负载均衡器的名称String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);// 创建并返回一个随机负载均衡器实例return new RandomLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name);}}

2.使用

@LoadBalancerClient(value = "cloud-production", configuration = RestTemplateConfig.class)

自带三个算法,轮询,随机和nacos

http://www.yayakq.cn/news/688172/

相关文章:

  • 如何做授权网站甘肃省建设厅官网网址
  • 三亚网站建设平台企业官网设计模板
  • 安什么网站建设广州黄埔网站建设公司
  • 将网站做成logo怎么做wordpress只在首页显示
  • 营销网站建设有哪些公司小程序登录不上去怎么办
  • 营销型网站建设费用南昌定制网站开发多少钱
  • 沈阳企业免费建站贵州建设监理协会网站
  • 河南南阳油田网站建设厦门做网站公司排名
  • 网站建设的步骤目标规划有哪些网站可以做设计竞标
  • 福建建设厅网站 资质旅游电子商务的网站建设
  • 网站宣传文案有哪些苏州响应式网站建设
  • 网站模板免费推荐北京游戏网站建设
  • 专业房产网站建设图片合成器在线制作
  • 备案修改网站名称中国疾病预防控制中心
  • 网站流程设计深圳东门街道办事处电话
  • 淄博网站建设常见问题西安企业查询
  • 网站负责人查询谷歌网页版入口在线
  • 太原电商网站设计罗田住房和城乡建设局网站
  • 勒流网站制作手机网站推荐哪些
  • 网站建设托管定制京东外贸人才网
  • 南宁建设职业技术学院招聘信息网站四川省建设厅工地安全网站
  • 阿里有做网站做网站用的小图标
  • 建设信息网的网站或平台登陆汕头生态建设典型案例
  • 嘉兴自助建站模板edu网站一般谁做的
  • vps设置网站访问用户权限防止恶意点击软件管用吗
  • 招标网站都有哪些货源一件代发从哪里找
  • 网站建设套餐是什么wordpress5.0发布文章
  • 太仓住房与城乡建设部网站千图网在线设计
  • 南京越城建设集团网站南宁seo服务优化
  • 诸暨做网站公司网站设计源代码