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ū)。
關(guān)鍵配置:
The configuration property
zuul.host.maxTotalConnections
andzuul.host.maxPerRouteConnections
, which default to 200 and 20 respectively.
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 filters
和Post filters
,我們需要定義2個(gè)filter,用來記錄開始和結(jié)束時(shí)間,很明顯,我們需要實(shí)現(xiàn)Pre
& Post
2個(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;
}
}
后續(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)