内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

[Springcloud一步步實(shí)現(xiàn)廣告系統(tǒng)]3.網(wǎng)關(guān)路由

Zuul(Router and Filter)

WIKI: 傳送門

站在用戶的角度思考問題,與客戶深入溝通,找到中原網(wǎng)站設(shè)計(jì)與中原網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋中原地區(qū)。

[Spring cloud 一步步實(shí)現(xiàn)廣告系統(tǒng)] 3. 網(wǎng)關(guān)路由

作用
  1. 認(rèn)證,鑒權(quán)(Authentication/Security)
  2. 預(yù)判(Insights)
  3. 壓力測試(Stress Testing)
  4. 灰度/金絲雀測試(Canary Testing)
  5. 動態(tài)路由(Dynamic Routing)
  6. 服務(wù)遷移(Service Migration)
  7. 降低負(fù)載(Load Shedding)
  8. 靜態(tài)響應(yīng)處理(Static Response handling)
  9. 主動/主動交換管理(Active/Active traffic management)

關(guān)鍵配置:

The configuration property zuul.host.maxTotalConnections and zuul.host.maxPerRouteConnections, which default to 200 and 20 respectively.

創(chuàng)建mscx-ad-zuul

三步曲創(chuàng)建法:

添加依賴
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>
加注解
@SpringCloudApplication
@EnableZuulProxy //啟用網(wǎng)關(guān)
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }
}
改配置
spring:
  application:
    name: ad-gateway-zuul
server:
  port: 1111
eureka:
  client:
    service-url:
      defaultZone: http://server1:7777/eureka/,http://server2:8888/eureka/,http://server3:9999/eureka/
  instance:
    hostname: ad-gateway-zuul
zuul:
  ignored-services: '*' # 過濾所有請求,除了下面routes中聲明過的服務(wù)
  routes:
    sponsor: #在路由中自定義服務(wù)路由名稱
      path: /ad-sponsor/**
      serviceId: mscx-ad-sponsor #微服務(wù)name
      strip-prefix: false
    search: #在路由中自定義服務(wù)路由名稱
      path: /ad-search/**
      serviceId: mscx-ad-search #微服務(wù)name
      strip-prefix: false
  prefix: /gateway/api
  strip-prefix: false #不對 prefix: /gateway/api 設(shè)置的路徑進(jìn)行截取,默認(rèn)轉(zhuǎn)發(fā)會截取掉配置的前綴
過濾器編寫

我們來編寫一個(gè)記錄請求時(shí)間周期的過濾器,根據(jù)Filter的三種類型:Pre filters,routing filtersPost filters,我們需要定義2個(gè)filter,用來記錄開始和結(jié)束時(shí)間,很明顯,我們需要實(shí)現(xiàn)Pre & Post2個(gè)過濾器。

@Slf4j
@Component
public class PreRequestFilter extends ZuulFilter {
    @Override
    public String filterType() {
        // pre filter
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        //獲取當(dāng)前請求的請求上下文
        RequestContext requestContext = RequestContext.getCurrentContext();
        //記錄請求進(jìn)入時(shí)間
        requestContext.set("api_request_time", System.currentTimeMillis());
        return null;
    }
}

---

@Slf4j
@Component
public class AccessLogFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        //需要最后一個(gè)執(zhí)行的filter
        return FilterConstants.SEND_RESPONSE_FILTER_ORDER - 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletRequest request = requestContext.getRequest();
        log.info("Request \"{}\" spent : {} seconds.", request.getRequestURI(),
                (System.currentTimeMillis() - Long.valueOf(requestContext.get("api_request_time").toString())) / 1000);
        return null;
    }
}
Gateway

后續(xù)更新

分享名稱:[Springcloud一步步實(shí)現(xiàn)廣告系統(tǒng)]3.網(wǎng)關(guān)路由
分享URL:http://www.rwnh.cn/article30/pgscso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈域名注冊、搜索引擎優(yōu)化微信小程序、建站公司

廣告

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

網(wǎng)站托管運(yùn)營
会理县| 吉隆县| 图木舒克市| 湟中县| 远安县| 张家港市| 西和县| 台山市| 涟水县| 老河口市| 汪清县| 宣化县| 九台市| 湄潭县| 怀宁县| 南和县| 淳化县| 广饶县| 白水县| 招远市| 成都市| 开鲁县| 汕尾市| 尉氏县| 宣汉县| 景德镇市| 柘荣县| 孟州市| 夹江县| 霍山县| 遂宁市| 水富县| 阳原县| 措美县| 无极县| 禹城市| 蕲春县| 宁阳县| 准格尔旗| 玉山县| 久治县|