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

学习html5的网站网络推广的公司是骗局吗

学习html5的网站,网络推广的公司是骗局吗,商标可以做网站吗,如何做优化网站的原创性文章1. OpenFeign 接口方法编写规范 1.1. 在编写 OpenFeign 接口方法时,需要遵循以下规范 1.1.1.1. 接口中的方法必须使用 RequestMapping、GetMapping、PostMapping 等注解声明 HTTP 请求的类型。 1.1.1.2. 方法的参数可以使用 RequestParam、RequestHeader、PathVa…

1. OpenFeign 接口方法编写规范

1.1. 在编写 OpenFeign 接口方法时,需要遵循以下规范

1.1.1.1. 接口中的方法必须使用 @RequestMapping、@GetMapping、@PostMapping 等注解声明 HTTP 请求的类型。
1.1.1.2. 方法的参数可以使用 @RequestParam、@RequestHeader、@PathVariable 等注解来制定如何传递 HTTP 请求的参数。
1.1.1.3. 可以使用 @RequestBody 来指定如何传递请求体中的参数。
1.1.1.4. 可以使用 @HearderMap 来传递头部信息。

1.2. 案例演示

1.2.1.1. Get 请求

get 请求,参数全放 URL 中,不建议放 Body,部分浏览器可能会限制不能读取 body 中的数据;

get 请求参数过长的话,也会有问题,适用于参数不长的场景。

目标接口方法:

@GetMapping("/getOrderByUserId")
public Result<List<OrderResponse>> getOrderByUserId(@RequestParam("userId") Long userId)

OpenFeign 接口方法

@GetMapping("/getOrderByUserId")
Result<List<OrderResponse>> getOrderByUserId(@RequestParam("userId") Long userId);
1.2.1.2. post 请求
1.2.1.2.1. @RequestBody

目标接口方法:

@RequestMapping(value = "/post1")
public Result<OrderResponse> post1(@RequestBody OrderRequest orderRequest)

OpenFeign 接口方法

@PostMapping("/post1")
Result<OrderResponse> post1(@RequestBody OrderRequest orderRequest);
1.2.1.2.2. URL 后面追加参数

除了放在 body 中的参数,还能直接 url 后面追加参数,@RequestParam 注解

例如:增加参数 token http:/XXXXXXXX?token=xxxxxx

目标接口方法:

@RequestMapping(value = "/post2")
public Result<OrderResponse> post2(@RequestBody OrderRequest orderRequest, @RequestParam("token") String token)

OpenFeign 接口方法:

@PostMapping("/post2")
Result<OrderResponse> post2(@RequestBody OrderRequest orderRequest, @RequestParam("token") String token);
1.2.1.2.3. url 中加参数

url 中追加参数,参数用 @PathVariable 注解

目标接口方法:

@RequestMapping(value = "/post3/{userId}")
public Result<OrderResponse> post3(@RequestBody OrderRequest orderRequest, @PathVariable("userId") Long userId)

OpenFeign 接口方法:

@PostMapping("/post3/{userId}")
Result<OrderResponse> post3(@RequestBody OrderRequest orderRequest, @PathVariable("userId") Long userId);

2. OpenFeign 的调用流程

3. OpenFeign 常用扩展点配置

openFeign 提供了很多的扩展机制,让用户可以更加灵活的使用。

3.1. 测试环境

速通版:git checkout v2.0.0 版本:

icoolkj-microservices-code 标签 - Gitee.com

会员服务调用订单服务。

3.2. 日志配置

配置 Feign 的日志,让 Feign 把请求信息输出,方便查找问题等。

日志级别有4 种:

  • NONE【性能最佳,默认值】:不记录任何日志。
  • BASIC【适用于生产环境追踪问题】:仅记录请求方法、URL、响应状态代码以及执行时间。
  • HEADERS:记录BASIC级别的基础上,记录请求和响应的header。
  • FULL【比较适用于开发及测试环境定位问题】:记录请求和响应的header、body和元数据。
3.2.1.1. 配置方式
3.2.1.1.1. Java Bean 方式

全局生效:利用 @Configuration 实现全局生效,对所有的微服务调用者都生效。

    1. 定义一个配置类,指定日志级别
// 注意: 此处配置@Configuration注解就会全局生效,如果想指定对应微服务生效,就不能配置@Configuration
@Configuration
public class FeignConfig {/*** 日志级别* @return*/@Beanpublic Logger.Level feignLoggerLevel(){return Logger.Level.FULL;}}
    1. 在 application.yml 中配置 Client 的日志级别才能正常输出日志

格式:logging.level.feign 接口包路径=debug

logging:level:com.icoolkj.mall.user.openfeign.demo.feign: debug
    1. 重启测试

分别选择日志级别进行测试,查看控制台输出结果信息。

局部生效:让指定的微服务生效,在 @FeignClient 注解中指定 configuration

@FeignClient(name = "icoolkj-mall-order01", path = "/api/order", configuration = OpenFeignConfig.class)
public interface OrderFeignService {

注意:此时配置类不能添加 @Configuration 注解 。

3.2.1.1.2. yum 配置文件方式

全局生效:配置{服务名} 为 default,对应的微服务调用者都生效。

spring:cloud:openfeign:client:config:default:loggerLevel: FULL

局部生效:配置{服务名}为具体的服务名(icoolkj-mall-order01),对调用的微服务提供者生效。

spring:cloud:openfeign:client:config:icoolkj-mall-order01:loggerLevel: FULL
3.2.1.1.3. 配置方式选择

建议使用 yml 配置,可以利用配置中心对配置进行统一管理。

3.3. 超时时间配置

3.3.1.1. OpenFeign 使用两个超时参数

connectionTimeout 可以防止由于较长的服务器处理时间而阻塞调用者。

readTimeout 从连接建立时开始应用,当返回响应花费太长时间时触发。

注意:OpenFeign 底层使用 LoadBalancer,但是超时以 OpenFeign 配置为准。

3.3.1.2. 配置方式
3.3.1.2.1. Java bean 方式

通过 Options 可以配置连接超时时间和读取超时时间,Options 的第一个参数是连接的超时时间(ms);第二个是请求处理的超时时间(ms)。

@Bean
public Request.Options options() {return new Request.Options(3000, 5000);
}
3.3.1.2.2. yml 配置文件方式
spring:cloud:openfeign:client:config:icoolkj-mall-order01:loggerLevel: FULL# 连接超时时间connectTimeout: 3000# 请求处理超时时间readTimeout: 5000
3.3.1.2.3. 测试配置是否生效

利用 Thread.sleep 来修改订单接口调用时间,验证是否超时。

3.4. 契约配置

Spring Cloud 在 Feign 的基础上做了扩展,可以让 Feign 支持 Spring MVC 的注解来调用。原生的 Feign 是不支持 Spring MVC 注解的,如果你想在 Spring Cloud 中使用原生的注解方式来定义客户端也是可以的,通过配置契约来改变这个配置,Spring Cloud 中默认的是 SpringMvcContract。

3.4.1.1. 配置方式
3.4.1.1.1. Java Bean 方式
@Bean
public Contract feignContract(){return new Contract.Default();
}
3.4.1.1.2. yml 配置文件方式
spring:cloud:openfeign:client:config:icoolkj-mall-order01:loggerLevel: FULL# 连接超时时间connectTimeout: 3000# 请求处理超时时间readTimeout: 5000# 指定contract: feign.Contract.Default

注意:修改契约配置后,OrderFeignService 不在支持 SpringMvc 的注解,需要使用 Feign 原生的注解。

Class OrderFeignService has annotations [FeignClient] that are not used by contract Default

@FeignClient(name = "icoolkj-mall-order01", path = "/api/order")
public interface OrderFeignService {// 使用 Feign 原生注解调用@RequestLine("GET /getOrderByUserId?userId={userId}")Result<List<OrderResponse>> getOrderByUserId(@Param("userId") Long userId);
}

3.5. 客户端组件配置

Feign 中默认使用 JDK 原生的 URLConnection 发送 HTTP 请求,没有连接池,我们可以集成别的组件来替换掉 URLConnection,比如 Apache HttpClient5,OKHttp。

Feign 发起调用真正执行逻辑:feign.Client#execute(扩展点)

3.5.1.1. 配置 Apache HttpClient5(推荐)
3.5.1.1.1. 引入依赖
<!-- Apache HttpClient5 -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-hc5</artifactId>
</dependency>
3.5.1.1.2. 修改 yml 配置,启用 Apache HttpClient5,引入依赖后默认启用的,可以忽略
spring:cloud:openfeign:httpclient:hc5:enabled: true

关于配置可参考:org.springframework.cloud.openfeign.FeignAutoConfiguration

3.5.1.1.3. 重启测试

调用会进入 feign.hc5.ApacheHttp5Client#execute

3.5.1.2. 配置 OkHttp
3.5.1.2.1. 引入依赖
<!-- okhttp -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-okhttp</artifactId>
</dependency>
3.5.1.2.2. 修改 yml 配置,将 Feign 的 HttpClient 禁用,启用 OkHttp。
spring:cloud:openfeign:httpclient:hc5:enabled: falseokhttp:enabled: true

关于配置可参考:org.springframework.cloud.openfeign.FeignAutoConfiguration

3.5.1.2.3. 重启测试

调用会进入 feign.okhttp.OkHttpClient#execute

3.6. GZIP 压缩配置

开启压缩可以有效节约网络资源,提升接口性能,我们可以配置 GZIP 来压缩数据

spring:openfeign:compression: # 配置 GZIP 来压缩数据request:enabled: truemime-types: text/xml,application/xml,application/jsonmin-request-size: 1024 # 最小请求压缩阈值response:enabled: true

关于配置可参考:

org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingAutoConfiguration

3.7. 编码器解码器配置

Feign 中提供了自定义的编码器解码器设置,同时也提供了多种编码器的实现,比如 Gson、Jaxb、Jackson。我们可以用不同的编码器解码器来处理数据的传输。如果你想传输 XML 格式的数据,可以自定义 XML 编码器解码器来实现,或者使用官方提供的 Jaxb。

扩展点:feign.codec.Encoder & feign.codec.Decoder

public interface Encoder {void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException;
}public interface Decoder {Object decode(Response var1, Type var2) throws IOException, DecodeException, FeignException;
}

3.8. 配置方式

3.8.1.1.1. 引入依赖
<!-- jackson -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-jackson</artifactId>
</dependency>
3.8.1.1.2. Java Bean 方式
@Bean
public Encoder encoder(){return new JacksonEncoder();
}@Bean
public Decoder decoder(){return new JacksonDecoder();
}
3.8.1.1.3. yml 配置文件方式
spring:cloud:openfeign:client:config:icoolkj-mall-order01:# 配置编码器解码器encoder: feign.jackson.JacksonEncoderdecoder: feign.jackson.JacksonDecoder

3.9. 拦截器配置

通过拦截器实现参数传递。

常用场景:统一添加 header 信息,比如向服务提供者传递全局事务 XID,会员 ID,认证 token 令牌,链路追踪的 traceID 等等。

扩展点:feign.RequestInterceptor

public interface RequestInterceptor {void apply(RequestTemplate var1);
}

每次 feign 发起 http 调用之前,会去执行拦截器中的逻辑。

3.9.1. 自定义拦截器实现认证逻辑

需求场景,微服务调用链路需要传递请求头的 token 信息

如果不做任何配置,直接使用 openFeign 在服务间进行调用就会丢失请求头。

解决方案:

3.9.1.1. 方案1:增加接口参数
@RequestMapping(value = "/api/product/getPriceProduct", method = RequestMethod.GET)  
String getPriceProduct(@RequestParam(value = "productId") Long productId, @RequestHeader(value = "token") String token);

该方案不好,代码有侵入性,需要开发人员每次手动获取和添加接口参数。

3.9.1.2. 方案2:添加拦截器

OpenFeign 在远程调用之前会遍历容器中的 RequestInterceptor,调用 RequestInterceptor 的 apply 方法,创建一个新的 Request 进行远程服务调用。因此可以通过实现 RequestInterceptor 给容器中添加自定义的 RequestInterceptor 实现类,这个类里面设置需要发送请求的参数,比如请求头信息,链路追踪信息等。

3.9.1.2.1. 代码实现拦截器:
@Slf4j
public class FeignAuthRequestInterceptor implements RequestInterceptor{@Overridepublic void apply(RequestTemplate template) {// 业务逻辑,模拟认证逻辑ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();if(null != requestAttributes){HttpServletRequest request = requestAttributes.getRequest();String access_token = request.getHeader("Authorization");log.info("从 Request 中解析请求头:{}", access_token);// 设置 tokentemplate.header("Authorization", access_token);}}
}
3.9.1.2.2. 配置拦截器生效

方式1,Java Bean

@Bean
public FeignAuthRequestInterceptor feignAuthRequestInterceptor(){return new FeignAuthRequestInterceptor();
}

方式2,yml 配置文件

spring:cloud:openfeign:client:config:icoolkj-mall-order01:  #对应微服务request-interceptors:   # 配置拦截器- com.icoolkj.mall.user.openfeign.demo.interceptor.FeignAuthRequestInterceptor
3.9.1.2.3. 重启测试

postman 中增加请求头参数 Authorization,查看会员服务 openFeign 日志是否有 Authorization 信息。


文章转载自:
http://lily.bfmq.cn
http://burundi.bfmq.cn
http://kitchenette.bfmq.cn
http://byword.bfmq.cn
http://feb.bfmq.cn
http://lumpenproletarian.bfmq.cn
http://justificative.bfmq.cn
http://gushing.bfmq.cn
http://wienie.bfmq.cn
http://cognition.bfmq.cn
http://gesticulant.bfmq.cn
http://sewer.bfmq.cn
http://aught.bfmq.cn
http://educt.bfmq.cn
http://homunculus.bfmq.cn
http://erythrogenic.bfmq.cn
http://saccharoidal.bfmq.cn
http://mensurate.bfmq.cn
http://netscape.bfmq.cn
http://sibling.bfmq.cn
http://psychogony.bfmq.cn
http://connectivity.bfmq.cn
http://longobard.bfmq.cn
http://underwood.bfmq.cn
http://dexterous.bfmq.cn
http://cyrenaicism.bfmq.cn
http://skutari.bfmq.cn
http://subdeb.bfmq.cn
http://gulfy.bfmq.cn
http://thalassian.bfmq.cn
http://unconstraint.bfmq.cn
http://inherency.bfmq.cn
http://submetallic.bfmq.cn
http://mildness.bfmq.cn
http://misbegot.bfmq.cn
http://boogeyman.bfmq.cn
http://gauffer.bfmq.cn
http://pseudopregnancy.bfmq.cn
http://jerid.bfmq.cn
http://illyrian.bfmq.cn
http://natriuretic.bfmq.cn
http://paraprotein.bfmq.cn
http://airboat.bfmq.cn
http://spaniard.bfmq.cn
http://capitalizable.bfmq.cn
http://rockford.bfmq.cn
http://ruefulness.bfmq.cn
http://starless.bfmq.cn
http://keeshond.bfmq.cn
http://wushu.bfmq.cn
http://liveable.bfmq.cn
http://somnambulance.bfmq.cn
http://spectate.bfmq.cn
http://vpd.bfmq.cn
http://received.bfmq.cn
http://gufa.bfmq.cn
http://reconquest.bfmq.cn
http://growlingly.bfmq.cn
http://nomistic.bfmq.cn
http://atomic.bfmq.cn
http://areographer.bfmq.cn
http://giant.bfmq.cn
http://keratopathy.bfmq.cn
http://mistook.bfmq.cn
http://minnesinger.bfmq.cn
http://urchin.bfmq.cn
http://volume.bfmq.cn
http://jerez.bfmq.cn
http://atmospherical.bfmq.cn
http://pavlovism.bfmq.cn
http://abaptiston.bfmq.cn
http://nonfreezing.bfmq.cn
http://extemporary.bfmq.cn
http://pretension.bfmq.cn
http://interfix.bfmq.cn
http://swimgloat.bfmq.cn
http://anestrus.bfmq.cn
http://nascence.bfmq.cn
http://ayc.bfmq.cn
http://limivorous.bfmq.cn
http://felicity.bfmq.cn
http://subfuscous.bfmq.cn
http://ivba.bfmq.cn
http://internuclear.bfmq.cn
http://hylic.bfmq.cn
http://wharfmaster.bfmq.cn
http://fibrillose.bfmq.cn
http://tenpenny.bfmq.cn
http://osteoradionecrosis.bfmq.cn
http://mid.bfmq.cn
http://windflower.bfmq.cn
http://attagal.bfmq.cn
http://goulash.bfmq.cn
http://flowerlet.bfmq.cn
http://cryptobranchiate.bfmq.cn
http://barometrical.bfmq.cn
http://caprolactam.bfmq.cn
http://skyful.bfmq.cn
http://mobbism.bfmq.cn
http://digenetic.bfmq.cn
http://www.dt0577.cn/news/58072.html

相关文章:

  • 第一源码网seo是什么专业
  • 电信专线可以做网站吗百度搜索seo优化技巧
  • 贵州建设职业技术学院网站查成绩哪些网站可以发广告
  • 做网站在经营范围内属于什么百度客服联系方式
  • 电子商务网站建设目的和意义seo招聘信息
  • 未及时取消网站备案可以放友情链接的网站
  • 厦门网站制作建设小说关键词搜索器
  • 推荐扬中网站建设营业推广方案
  • 北京代理记账财务公司seo关键词排名
  • 网站怎么做国际化百度超级链
  • 手机端网站建设要点seo工作职位
  • 做淘宝联盟网站东莞优化疫情防控措施
  • 杭州雄飞网站建设网络公司线上推广方案怎么写
  • 网站设计用什么软件实现高级seo培训
  • 怎样制作一个网站百度联盟是什么
  • 东莞手机建网站免费发布信息平台有哪些
  • 有没有99块钱做网站中国域名网官网
  • html5响应式布局网站360优化大师下载
  • 企业服务平台官网入口百度竞价优化排名
  • 优化方案英语答案申泽seo
  • 从零开始学wordpressseo的工作流程
  • 批发网站建设站长统计在线观看
  • 男女做那个的的视频网站网络营销的一般流程
  • sns有哪些著名的网站互动营销名词解释
  • 在哪家公司建设网站好搜索引擎推广试题
  • html5做网站seo还有用吗
  • 百度seo快速排名优化软件优化设计电子版
  • 萧山做网站公司新站点seo联系方式
  • 如何投诉做网站的公司免费网络营销推广软件
  • jquery mobile 做的网站净水器十大品牌