欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

SpringCloudFeign高級(jí)應(yīng)用的示例分析-創(chuàng)新互聯(lián)

小編給大家分享一下Spring Cloud Feign高級(jí)應(yīng)用的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)主營(yíng)新林網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開(kāi)發(fā),新林h5重慶小程序開(kāi)發(fā)搭建,新林網(wǎng)站營(yíng)銷(xiāo)推廣歡迎新林等地區(qū)企業(yè)咨詢(xún)

1.使用feign進(jìn)行服務(wù)間的調(diào)用

Spring boot2X Consul如何使用Feign實(shí)現(xiàn)服務(wù)調(diào)用

2.開(kāi)啟gzip壓縮

Feign支持對(duì)請(qǐng)求與響應(yīng)的壓縮,以提高通信效率,需要在服務(wù)消費(fèi)者配置文件開(kāi)啟壓縮支持和壓縮文件的類(lèi)型

添加配置

feign.compression.request.enabled=true
feign.compression.response.enabled=true
feign.compression.request.mime-types=text/xml,application/xml,application/json
feign.compression.request.min-request-size=2048

3.開(kāi)啟日志

配置

logging.level.com.xyz.comsumer.feign.RemoteHelloService=debug

添加FeignLogConfig類(lèi)

package com.xyz.comsumer.configure;

import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignLogConfig {
  @Bean
  Logger.Level feignLogger(){
    return Logger.Level.FULL;
  }
}

輸出

2019-12-07 23:23:03.630 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] <--- HTTP/1.1 200 (671ms)
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] content-length: 14
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] content-type: text/plain;charset=UTF-8
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] date: Sat, 07 Dec 2019 15:23:03 GMT
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] vary: Origin
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] vary: Access-Control-Request-Method
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] vary: Access-Control-Request-Headers
2019-12-07 23:23:03.631 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] 
2019-12-07 23:23:03.632 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] hello,provider
2019-12-07 23:23:03.632 DEBUG 2668 --- [vice-provider-1] c.xyz.comsumer.feign.RemoteHelloService : [RemoteHelloService#hello] <--- END HTTP (14-byte body)

說(shuō)明:

  Feign日志記錄只能響應(yīng)DEBUG日志級(jí)別

對(duì)每一個(gè)Feign客戶端,可以配置一個(gè)Logger.Level對(duì)象,通過(guò)該對(duì)象控制日志輸出內(nèi)容。

Logger.Level有如下幾種選擇:

NONE, 不記錄日志 (默認(rèn))。

BASIC, 只記錄請(qǐng)求方法和URL以及響應(yīng)狀態(tài)代碼和執(zhí)行時(shí)間。

HEADERS, 記錄請(qǐng)求和應(yīng)答的頭的基本信息。

FULL, 記錄請(qǐng)求和響應(yīng)的頭信息,正文和元數(shù)據(jù)。

4.替換JDK默認(rèn)的URLConnection為okhttp

在默認(rèn)情況下 spring cloud feign在進(jìn)行各個(gè)子服務(wù)之間的調(diào)用時(shí),http組件使用的是jdk的HttpURLConnection

服務(wù)之間調(diào)用使用的HttpURLConnection,效率非常低

為了提高效率,可以通過(guò)連接池提高效率

使用okhttp,能提高qps,因?yàn)閛khttp有連接池和超時(shí)時(shí)間進(jìn)行調(diào)優(yōu)

添加依賴(lài)

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-okhttp</artifactId>
</dependency>

修改配置

禁用默認(rèn)的http,啟用okhttp

feign.okhttp.enabled=true
feign.httpclient.enabled=false

添加FeignOkHttpConfig類(lèi)

package com.xyz.comsumer.configure;

import feign.Feign;
import okhttp3.ConnectionPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@ConditionalOnClass(Feign.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)
public class FeignOkHttpConfig {

  @Bean
  public okhttp3.OkHttpClient okHttpClient(){
    return new okhttp3.OkHttpClient.Builder()
        .readTimeout(10, TimeUnit.SECONDS)
        .connectTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(20, TimeUnit.SECONDS)
        .retryOnConnectionFailure(true)
        .connectionPool(new ConnectionPool())
        .build();
  }
}

5.超時(shí)設(shè)置

Feign調(diào)用服務(wù)的默認(rèn)時(shí)長(zhǎng)是1秒鐘

hystrix的超時(shí)時(shí)間

hystrix.command.default.execution.timeout.enabled=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000

說(shuō)明:

  hystrix.command.default.execution.timeout.enabled 執(zhí)行是否啟用超時(shí),默認(rèn)啟用true

  hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 命令執(zhí)行超時(shí)時(shí)間,默認(rèn)1000ms

  常用的配置還有

    hystrix.command.default.execution.isolation.strategy 隔離策略,默認(rèn)是Thread, 可選THREAD|SEMAPHORE,建議選擇SEMAPHORE

Feign 的負(fù)載均衡底層用的就是 Ribbon

ribbon的超時(shí)時(shí)間

ribbon.ReadTimeout=10000
ribbon.ConnectTimeout=10000

6.使用hystrix進(jìn)行熔斷、降級(jí)處理

feign啟用hystrix,才能熔斷、降級(jí)

feign.hystrix.enabled=true

hystrix服務(wù)降級(jí)處理

RemoteHelloServiceFallbackImpl

package com.xyz.comsumer.feign.fallback;

import com.xyz.comsumer.feign.RemoteHelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteHelloServiceFallbackImpl implements RemoteHelloService {
  private final Logger logger = LoggerFactory.getLogger(RemoteHelloServiceFallbackImpl.class);

  @Override
  public String hello() {
    logger.error("feign 查詢(xún)信息失敗:{}");
    return null;
  }
}

以上是“Spring Cloud Feign高級(jí)應(yīng)用的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前名稱(chēng):SpringCloudFeign高級(jí)應(yīng)用的示例分析-創(chuàng)新互聯(lián)
文章源于:http://aaarwkj.com/article16/hoigg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)Google、響應(yīng)式網(wǎng)站、網(wǎng)站營(yíng)銷(xiāo)全網(wǎng)營(yíng)銷(xiāo)推廣、軟件開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
夫妻性生活视频在线免费看| 少妇按摩高潮呻吟av| 日本区一区二区三高清视频 | 国产精品一区二区三区日本| 人妻丰满熟妇九九久久| 男女午夜激情四射视频| 狠狠久久五月综合色和啪| 国产美女口爆吞精久久| 日本岛国大片在线视频| 亚洲黄色av网站在线| 97视频观看免费观看| 精品久久久久久亚洲电影| 麻豆乱淫一区二区三爱免费| 亚洲成年人黄片在线播放| 国产精品久久久在线视频| 亚洲中文字幕一区乱码| 亚洲欧美综合伊人看片综合| 免费人妻aⅴ中文字幕| 日本经典三级视频在线观看| 国产一级黄色性生活片| 亚洲中文字幕少妇视频| 亚乱熟女一区二区三区| 九九免费在线视频观看| 色婷婷亚洲综合色一区二区| 在线播放国内自拍情侣酒店| 中文字幕国产成人在线视频| 日韩欧美亚洲国产另类| 粉嫩极品美女国产精品| 午夜黄色福利在线观看| 内地精品露脸自拍视频| 国产精品毛片在线看不卡| 亚洲欧美日韩午夜在线| 亚洲熟妇av一区二区三区l| 蜜臀国产综合久久第一页| 欧美日本道一区二区三区| 婷婷丁香六月激情综合| 精品国产一区二区三区av在线| 日韩欧美二区三区在线| 精品人妻av区久久久| 国产原创中文剧情性感av| 日韩人妖视频在线观看|