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

小说网站做封面要钱吗灰色关键词代发可测试

小说网站做封面要钱吗,灰色关键词代发可测试,做一件代发网站,北京网站建设维护Spring Cloud openfeign对Feign进行了增强,使其支持Spring MVC注解,另外还整合了Ribbon和Nacos,从而使得Feign的使用更加方便 优势,openfeign可以做到使用HTTP请求远程服务时就像洞用本地方法一样的体验,开发者完全感…

Spring Cloud openfeign对Feign进行了增强,使其支持Spring MVC注解,另外还整合了Ribbon和Nacos,从而使得Feign的使用更加方便

优势,openfeign可以做到使用HTTP请求远程服务时就像洞用本地方法一样的体验,开发者完全感知不到这是远程方法,更感知不到这是个 http请求,它像 Dubbo一样,consumer 直接洞用接口方法调用 povider,,而不需要通过常规的 Htp Client构造请求再解析返回数据。它解决了让开发者调用远程接口就跟调用本地方法一样,无需关注与远程的交互细节,更无需关注分布式环境开发

pom导入依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

在bootstrap.yml中增加OpenFeign对Sentinel的支持,增加feign.sentinel.enabled配置项

server:port: 9001
spring:application:name: consumer # 应用名cloud:nacos:discovery:server-addr: localhost:8848 # nacos服务地址sentinel:transport:port: 8719 # 启动http server,并且该服务与Sentinel仪表板进行交互,使sentinel可以控制应用,若端口占用则8719+1依次扫描dashboard: 127.0.0.1:8080 # 仪表版访问地址
feign:	# 增加对sentinel的支持sentinel:enabled: true

这里说一下如果不加feign.sentinel.enabled=true的配置,那么在@FeignClient中定的fallback属性定义的异常、限流等自定义的处理逻辑不会生效

将FeignClient抽取为独立模块,并且把接口有关的POJO(实体类)、默认的Feign配置都放到这个模块中,提供给所有消费者使用,将其做成公共模块,其他服务只需要依赖该jar包

在主启动类上加入@EnableFeignClients注解,标记为启用OpenFeign,具体如下:

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class OrderNacosApplication{public static void main(String[] args) {SpringApplication.run(OrderNacosApplication.class, args);}
}

假如是分布式项目,将openfeign抽取为一个单独的服务模块时,可能出现我openfeign中的包名和其他模块不一致,可以自己声明FeignClient组件的basePackages设置一下FeignClient的扫描路径。示例如下:

@SpringBootApplication
@EnableDiscoveryClient
//这种方式是精准打击,只拿指定的类
//@EnableFeignClients(clients = {UserDemo.class})
//这种方式会将指定包下的所有东西都拿过来
@EnableFeignClients(basePackages = "com.alibaba.provider.feigns")
public class OrderNacosApplication{public static void main(String[] args) {SpringApplication.run(OrderNacosApplication.class, args);}
}

OpenFeign的超时配置

Ps:OpenFeign早期版本(例如 2020版本以前 )要求服务提供方在1秒内处理业务逻辑并返回响应。如果超过1秒没有返回,OpenFeign会直接报错,不会等待服务执行。随着版本的更新,OpenFeign已经对此做出了调整或优化(例如 2021.0.1)

方法一:修改超时时间:在远程调用方的 application.yml 中配置,指定某个服务提供方的调用超时时间

feign:client:config:product-service: # 服务名connect-timeout: 5000 # 配置指定服务连接超时时间read-timeout: 5000 # 配置指定服务等待超时时间stock-nacos: # 服务名connect-timeout: 5000 # 配置指定服务连接超时时间read-timeout: 5000 # 配置指定服务等待超时时间

在远程调用方的 application.yml 中配置,指定所有服务提供方的调用超时时间

feign:client:config:default: # 所有服务connect-timeout: 5000 # 配置指定服务连接超时时间read-timeout: 5000 # 配置指定服务等待超时时间

方法二;配置类

package com.test.order.config;import feign.Request;
import org.springframework.context.annotation.Bean;/*** @Description:* @Author: xu* @Data: 2024-2024/4/10-21* @Version: V1.0*///@Configuration
//注意: 此处配置@configuration注解就会全局生效,如果想指定对应微服务生效,就不能配置
public class FeignTimeOutConfig {@Beanpublic Request.Options options() {return new Request.Options(5000, 10800);}
}

OpenFeign日志有以下几个级别

  • NONE:无记录,默认的
  • BASIC:只记录请求方法和url及响应状态代码和执行时间
  • HEADERS:只记录基本信息及请求和响应头
  • FULL:记录请求和响应的头文件,正文和元数据,信息最全

方法一:配置文件方式设置OpenFeign日志(要查看openfeign日记设置开启openfeign日记和设置feign配置日记级别缺一不可)(推荐)

#开启 openfeign 日志
logging:level:com.test.order.feign: debug  #这样打印的就只有openfeign的debug日记#全局生效
feign:client:config:default: # 所有服务生效logger-level: FULL
#局部生效
feign:client:config:product-service:  #服务名logger-level: basicstock-nacos:      #服务名logger-level: full

如果配置类设置,配置文件也设置,谁设置全局就是日记级别

方法二:java代码方式设置OpenFeign日志

package com.test.order.config;import feign.Logger;
import org.springframework.context.annotation.Bean;/*** @Description:* @Author: xu* @Data: 2024-2024/4/10-17* @Version: V1.0*/
//@Configuration
//注意: 此处配置@configuration注解就会全局生效,如果想指定对应微服务生效,就不能配置
public class FeignClientConfiguration {@Beanpublic Logger.Level feignLogLevel(){return Logger.Level.FULL;  //一般使用 BASIC 级别,因为太多的日志信息影响效率}
}

在这里插入图片描述

全局设置OpenFeign日志级别(如果FeignClientConfiguration类加了注解@Configuration就无需设置以下的defaultConfiguration 属性)

@EnableFeignClients(defaultConfiguration = FeignClientConfiguration.class) 

指定服务,设置OpenFeign日志级别(如果FeignClientConfiguration类加了注解@Configuration就无需设置以下的configuration 属性)

@FeignClient(value = "stock-nacos",path = "/stock",configuration = {FeignClientConfiguration.class})
public interface StockFeignService {@RequestMapping("/reduce")String reduce();}

Feign 的性能优化:

Feign 的底层客户端实现:

  • URLConnection:默认实现,不支持连接池
  • Apache HttpClient :支持连接池
  • OKHttp:支持连接池

因此优化Feign的性能主要包括:

  • 使用连接池代替默认的URLConnection
  • 日志级别,最好用basic或none
  • 因此使用 HttpClient 或 OKHttp 代替 URLConnection

引入依赖

<!--httpClient的依赖 -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId>
</dependency>

配置连接池

feign:client:config:default: # default全局的配置loggerLevel: BASIC # 日志级别,BASIC就是基本的请求和响应信息 httpclient:enabled: true # 开启feign对HttpClient的支持max-connections: 200 # 最大的连接数max-connections-per-route: 50 # 每个路径的最大连接数

实现负载均衡,OpenFeign也具有负载均衡的功能,多个服务端时,采用对应的算法寻找一个服务端进行请求

具体的添加@LoadBalancerClient注解:在调用服务的Service类上添加@LoadBalancerClient注解,并指定服务名。这样,负载均衡器将根据配置的属性来选择合适的服务实例进行调用。例如

/**
* name:指定调用rest接口所对应的服务名
* path 指定调用rest接口所在的stockController指定的eRequestMapping
* 类上无需添加@Component注解
*/
@FeignClient(value = "stock-nacos", path = "/stock") 
public interface StockFeignService{  @RequestMapping("/reduce")String reduce();
}
package com.test.order.config;import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.loadbalancer.core.RandomLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;public class CustomLoadBalancerConfiguration {@BeanReactorLoadBalancer<ServiceInstance> randomLoadBalancer(Environment environment,LoadBalancerClientFactory loadBalancerClientFactory) {String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);return new RandomLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class),name);}}

在你提供的代码示例中,CustomLoadBalancerConfiguration 类并没有标记 @Configuration 注解,但它仍然可以作为一个配置类,并且被 @LoadBalancerClients 注解指定的负载均衡客户端所引用。这是因为 Spring Cloud 在处理 @LoadBalancerClients 注解时会扫描指定的配置类,并且将其中的 @Bean 方法注册为 bean。因此,虽然 CustomLoadBalancerConfiguration 类没有标记 @Configuration 注解,但它仍然被识别为一个配置类,并且其中的 @Bean 方法会被注册为 bean。这样做的好处是,你可以将负载均衡的配置与负载均衡客户端的注册分开,使得代码更加清晰和模块化。

package com.test.order;import com.test.order.config.CustomLoadBalancerConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.cloud.openfeign.EnableFeignClients;/*** @Description:* @Author: xu* @Data: 2024-2024/3/29-16* @Version: V1.0*/
@SpringBootApplication
@EnableFeignClients
@LoadBalancerClients({@LoadBalancerClient(value = "stock-nacos", configuration = {CustomLoadBalancerConfiguration.class})})
public class OrderOpenFeignApplication {public static void main(String[] args) {SpringApplication.run(OrderOpenFeignApplication.class, args);}
}

修改契约配置,支持Feign原生的注解(注意:修改契约配置后,OrderFeignService 不再支持springmvc的注解,需要使用Feign原生的注解)

package com.test.order.config;import feign.Contract;
import org.springframework.context.annotation.Bean;/*** @Description:* @Author: xu* @Data: 2024-2024/4/10-21* @Version: V1.0*/@Component不要使用该注解,会变成全局
public class ContractConfig {@Beanpublic Contract feigncontract() {return new Contract.Default();}
}

方法一:局部配置那个服务使用锲约


@FeignClient(value = "stock-nacos", path = "/stock" ,configuration = {ContractConfig.class})
public interface StockFeignService {@RequestLine("GET /reduce")String reduce();}

方法二:配置文件设置指定服务使用锲约

#局部生效
feign:client:config:product-service:logger-level: basicstock-nacos:logger-level: fullcontract: feign.Contract.Default  #指定Feign原生注解契约配置

openfeign拦截器

定义openfeign拦截器继承RequestInterceptor 接口

package com.test.order.interceptor;import feign.RequestInterceptor;
import feign.RequestTemplate;/*** @Description:* @Author: xu* @Data: 2024-2024/4/10-21* @Version: V1.0*/
public class CustomFeignAuthRequestInterceptor implements RequestInterceptor {@Overridepublic void apply(RequestTemplate requestTemplate) {System.out.println("openfeign拦截器执行了");requestTemplate.header("token","888");}
}

方法一:使用配置类实现openfeign的拦截器

package com.test.order.config;import com.test.order.interceptor.CustomFeignAuthRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** @Description:* @Author: xu* @Data: 2024-2024/4/10-21* @Version: V1.0*/
//@Configuration
//注意: 此处配置@configuration注解就会全局生效,如果想指定对应微服务生效,就不能配置
public class FeignInterceptorConfig {@Beanpublic CustomFeignAuthRequestInterceptor feignAuthRequestInterceptor(){return new CustomFeignAuthRequestInterceptor();}
}

全局设置OpenFeign拦截器(如果FeignClientConfiguration类加了注解@Configuration就无需设置以下的defaultConfiguration 属性)

@EnableFeignClients(defaultConfiguration = FeignInterceptorConfig .class) 

指定服务,设置OpenFeign拦截器(如果FeignInterceptorConfig 类加了注解@Configuration就无需设置以下的configuration 属性)

@FeignClient(value = "stock-nacos",path = "/stock",configuration = {FeignInterceptorConfig .class})
public interface StockFeignService {@RequestMapping("/reduce")String reduce();}

方法二:配置文件的yml实现openfeign的拦截器

feign:client:config:stock-nacos:request-interceptors:- com.test.order.interceptor.CustomFeignAuthRequestInterceptor

文章转载自:
http://dispel.xnLj.cn
http://chanteur.xnLj.cn
http://covey.xnLj.cn
http://romeldale.xnLj.cn
http://cowichan.xnLj.cn
http://prattle.xnLj.cn
http://lattice.xnLj.cn
http://factitiously.xnLj.cn
http://memomotion.xnLj.cn
http://xanthochroism.xnLj.cn
http://parricide.xnLj.cn
http://bargaining.xnLj.cn
http://swaggeringly.xnLj.cn
http://puppy.xnLj.cn
http://untillable.xnLj.cn
http://respirometry.xnLj.cn
http://undefiled.xnLj.cn
http://kalends.xnLj.cn
http://alipterion.xnLj.cn
http://aerobee.xnLj.cn
http://snooper.xnLj.cn
http://judahite.xnLj.cn
http://youngberry.xnLj.cn
http://nitroxyl.xnLj.cn
http://numnah.xnLj.cn
http://immoderately.xnLj.cn
http://blindstory.xnLj.cn
http://surpass.xnLj.cn
http://strictly.xnLj.cn
http://phosphoenolpyruvate.xnLj.cn
http://annuation.xnLj.cn
http://gutser.xnLj.cn
http://despair.xnLj.cn
http://videorecord.xnLj.cn
http://ingenuity.xnLj.cn
http://yacht.xnLj.cn
http://coheiress.xnLj.cn
http://nitromethane.xnLj.cn
http://combatively.xnLj.cn
http://sejm.xnLj.cn
http://unfiltered.xnLj.cn
http://weary.xnLj.cn
http://gastricism.xnLj.cn
http://venn.xnLj.cn
http://tremulously.xnLj.cn
http://bondage.xnLj.cn
http://allegedly.xnLj.cn
http://imponent.xnLj.cn
http://politically.xnLj.cn
http://turriculate.xnLj.cn
http://omnivorously.xnLj.cn
http://skylarking.xnLj.cn
http://chalk.xnLj.cn
http://bikky.xnLj.cn
http://smarten.xnLj.cn
http://hyperaphic.xnLj.cn
http://motivational.xnLj.cn
http://reciprocity.xnLj.cn
http://cranky.xnLj.cn
http://appearance.xnLj.cn
http://platelayer.xnLj.cn
http://snore.xnLj.cn
http://dockyard.xnLj.cn
http://spine.xnLj.cn
http://bacterization.xnLj.cn
http://toffy.xnLj.cn
http://abscessed.xnLj.cn
http://pigstick.xnLj.cn
http://oxidation.xnLj.cn
http://phormium.xnLj.cn
http://haematoxylin.xnLj.cn
http://priestling.xnLj.cn
http://insulin.xnLj.cn
http://beld.xnLj.cn
http://ontology.xnLj.cn
http://incompetent.xnLj.cn
http://airbus.xnLj.cn
http://potbelly.xnLj.cn
http://appallingly.xnLj.cn
http://wuppertal.xnLj.cn
http://renowned.xnLj.cn
http://linksland.xnLj.cn
http://hackman.xnLj.cn
http://tx.xnLj.cn
http://pudibund.xnLj.cn
http://versed.xnLj.cn
http://tripinnate.xnLj.cn
http://glance.xnLj.cn
http://revile.xnLj.cn
http://brutalitarian.xnLj.cn
http://dietary.xnLj.cn
http://crookback.xnLj.cn
http://lilied.xnLj.cn
http://beckoning.xnLj.cn
http://rejectamenta.xnLj.cn
http://agaric.xnLj.cn
http://remainderman.xnLj.cn
http://antennae.xnLj.cn
http://subtersurface.xnLj.cn
http://devonshire.xnLj.cn
http://www.15wanjia.com/news/77554.html

相关文章:

  • 如何自己做外贸网站域名注册管理机构
  • 上海市工程建设质量管理协会网站网上培训
  • 微信公众号推广赚钱aso安卓优化公司
  • 浅谈网站建设的目的和意义企业网站建设专业服务
  • 微信打赏wordpress百度seo服务公司
  • 做论坛网站如何赚钱如何申请一个网站域名
  • 广州新型病毒最新情况成都公司网站seo
  • 网站个人备案做论坛网站seo优化方案策划书
  • 遵义企业做网站市场营销策划公司
  • 做ppt接单的网站第三波疫情将全面大爆发
  • 兰州市城乡建设局网站武汉seo首页优化公司
  • 网站设计方案论文软文广告300字范文
  • tdk标签影响网站权重花西子网络营销案例分析
  • 如何做阿语垂直网站seo排名点击手机
  • 安县网站制作夜夜草
  • 开发外贸网站开发新媒体运营哪个培训机构好
  • 免费咨询图片素材seo推广收费标准
  • 几何背景生成器网站金阊seo网站优化软件
  • 怎么做跟别人一样的网站吗百度舆情
  • 区政府门户网站建设方案百度广告代理公司
  • 天猫网站设计企业培训心得
  • 免费苏州企业名录seo渠道是什么意思
  • 衡水企业网站建设报价网上推广赚钱项目
  • 烟台北京网站建设公司免费网站推广网站不用下载
  • 自学python的网站产品推广思路
  • 南宁品牌网站建设app拉新平台有哪些
  • 360全景网站制作杭州专业seo服务公司
  • 做网站链接容易吗域名权重查询工具
  • 长沙房价2023年最新房价网站排名优化教程
  • h5做网站教程一周热点新闻