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

罗定建设局网站朝阳seo排名

罗定建设局网站,朝阳seo排名,建设网站步骤是,衡水做wap网站价格feign 配置 针对单个feign接口进行配置feign:client:config:# feignName 注意这里与contextId一致,不能写成name(FeignClientFactoryBean#configureFeign)# 不能写成 client-b (微服务名称),否则不生效helloFeignClient: # conte…

feign 配置

  1. 针对单个feign接口进行配置
    feign:client:config:# feignName 注意这里与contextId一致,不能写成name(FeignClientFactoryBean#configureFeign)# 不能写成 client-b (微服务名称),否则不生效helloFeignClient: # contextIdconnectTimeout: 50000 # 连接超时时间readTimeout: 50000 # 读超时时间loggerLevel: full #配置Feign的日志级别#default:# 其他默认配置
    
  2. feign 全局默认配置
    feign:client:config:default:connectTimeout: 50000 # 连接超时时间readTimeout: 50000 # 读超时时间loggerLevel: full #配置Feign的日志级别
    
  3. feign开启gzip支持
    feign:compression:request:enabled: truemime-types: "text/xml, application/xml, application/json"min-request-size: 2048response:enabled: true # 配置相应GZIP压缩
    

开启gzip支持后接口调用处理(方式一)

  1. feign接口使用ResponseEntity<byte []>接收数据
    @FeignClient(contextId = "testFeignClient", name = "client-a")
    public interface TestFeignClient {@GetMapping(value = "/userInfo")ResponseEntity<byte []> userInfoCompress(@RequestParam("username") String username, @RequestParam("address") String address) ;
    }
    
  2. 编写单元测试(注意需要对byte[] 数组使用Gzip解压)
    @Slf4j
    public class TestFeignClientTest extends BaseJunitTest {@Autowiredprivate TestFeignClient testFeignClient ;@Testpublic void userInfoCompress() throws IOException {String username = "张三" ;String address = "北京" ;ResponseEntity<byte[]> responseEntity = testFeignClient.userInfoCompress(username, address);byte[] compressed = responseEntity.getBody();String decompressValue = GzipUtils.decompress(compressed);log.info("value : {}", decompressValue);}
    }
    
  3. 编写gzip解压缩工具类
    public final class GzipUtils {public static String decompress(byte [] compressed) throws IOException {final StringBuilder output = new StringBuilder() ;try(GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, StandardCharsets.UTF_8))){String line ;while ((line = bufferedReader.readLine()) != null){output.append(line) ;}return output.toString() ;}}
    }
    

开启gzip支持后接口调用处理(方式二)

  1. 编写Decoder (内部使用方式一的Gzip解压缩工具类GzipUtils)
    public class FeignResponseDecoder implements Decoder {private final Decoder delegate;public FeignResponseDecoder(Decoder delegate) {Objects.requireNonNull(delegate, "Decoder must not be null. ");this.delegate = delegate;}@Overridepublic Object decode(Response response, Type type) throws IOException {Collection<String> values = response.headers().get(HttpEncoding.CONTENT_ENCODING_HEADER);if (Objects.nonNull(values) && !values.isEmpty() && values.contains(HttpEncoding.GZIP_ENCODING)) {byte[] compressed = Util.toByteArray(response.body().asInputStream());if ((compressed == null) || (compressed.length == 0)) {return delegate.decode(response, type);}//decompression part//after decompress we are delegating the decompressed response to default//decoderif (isCompressed(compressed)) {String decompressValue = GzipUtils.decompress(compressed);Response decompressedResponse = response.toBuilder().body(decompressValue.getBytes()).build();return delegate.decode(decompressedResponse, type);} else {return delegate.decode(response, type);}} else {return delegate.decode(response, type);}}private static boolean isCompressed(final byte[] compressed) {return (compressed[0] == (byte) (GZIPInputStream.GZIP_MAGIC)) && (compressed[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8));}
    }
    
  2. 将Decoder加入到Spring容器管理
    @Configuration
    public class AppConfig{@Beanpublic Decoder GZIPResponseDecoder(ObjectFactory<HttpMessageConverters> messageConverters) {Decoder decoder = new FeignResponseDecoder(new SpringDecoder(messageConverters));return decoder;}
    }
    
  3. feign接口使用普通java对象接收数据
    @FeignClient(contextId = "testFeignClient", name = "client-a")
    public interface TestFeignClient {@GetMapping("/userInfo")UserInfoVO userInfo(@RequestParam("username") String username, @RequestParam("address") String address) ;
    }
    
  4. 编写单元测试
    @Slf4j
    public class TestFeignClientTest extends BaseJunitTest {@Autowiredprivate TestFeignClient testFeignClient ;@Testpublic void userInfo(){String username = "张三" ;String address = "北京" ;UserInfoVO userInfo = testFeignClient.userInfo(username, address);log.info("user info : {}", userInfo);}
    }
    

其他知识点补充

  1. SpringBoot服务提供者开启gizp压缩
    server:port: 7070compression:enabled: true
    
http://www.shuangfujiaoyu.com/news/18853.html

相关文章:

  • 怀柔建设网站经典软文案例
  • 房产中介在线咨询镇海seo关键词优化费用
  • 怎么做网站和服务器吗电脑培训班一般要学多久
  • 麒麟区住房和城乡建设局网站网站快速排名优化哪家好
  • 国外机械做的好的网站什么是网络营销策略
  • 做好一个网站需要多久seo关键词优化举例
  • wordpress查询置顶文章贵港seo
  • 手机移动网站建设软件开发自学步骤
  • 重庆网站建设找承越凡科官网免费制作小程序
  • 南京网站搜索引擎优化电脑优化软件排行榜
  • 中国制造网介绍sem和seo是什么职业
  • 免费com域名注册网站东莞网站建设方案外包
  • 西乡做网站公司网站关键词优化怎么做的
  • 西安做网站选哪家公司推广赚钱的软件排行
  • 龙之向导外贸网站 网络服务海外推广解决方案
  • 网站怎么维护更新站长工具ping
  • 建设银行在上海的招聘网站seo工具
  • 后台给网站做关键字东莞网站开发公司
  • 广州 网站开发十大接单推广平台
  • 蛋糕行业网站建设方案seo搜索引擎优化名词解释
  • 哪个网站专门做灵异文sem和seo是什么意思
  • 郑州便民服务平台成都搜索优化排名公司
  • 网站开发和网页设计的区别打开百度搜索引擎
  • 烟台优化网站建设数据网站
  • 如何做网站 frontpage网络推广方案七步法
  • 批发电商做的好的网站搜索引擎推广方法
  • wordpress 编辑index温州seo按天扣费
  • 北京网站seo价格桌子seo关键词
  • 饰品企业网站建设合肥做网络推广的公司
  • 万户网络做网站怎么样南昌搜索引擎优化