這篇文章主要介紹“spring boot中WebFluxTagsProvider的作用是什么”,在日常操作中,相信很多人在spring boot中WebFluxTagsProvider的作用是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”spring boot中WebFluxTagsProvider的作用是什么”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
在南部等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),南部網(wǎng)站建設(shè)費(fèi)用合理。
本文主要研究一下webflux的WebFluxTagsProvider
spring-boot-actuator-2.1.5.RELEASE-sources.jar!/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsProvider.java
@FunctionalInterface public interface WebFluxTagsProvider { /** * Provides tags to be associated with metrics for the given {@code exchange}. * @param exchange the exchange * @param ex the current exception (may be {@code null}) * @return tags to associate with metrics for the request and response exchange */ Iterable<Tag> httpRequestTags(ServerWebExchange exchange, Throwable ex); }
WebFluxTagsProvider接口定義了httpRequestTags方法
spring-boot-actuator-2.1.5.RELEASE-sources.jar!/org/springframework/boot/actuate/metrics/web/reactive/server/DefaultWebFluxTagsProvider.java
public class DefaultWebFluxTagsProvider implements WebFluxTagsProvider { @Override public Iterable<Tag> httpRequestTags(ServerWebExchange exchange, Throwable exception) { return Arrays.asList(WebFluxTags.method(exchange), WebFluxTags.uri(exchange), WebFluxTags.exception(exception), WebFluxTags.status(exchange), WebFluxTags.outcome(exchange)); } }
DefaultWebFluxTagsProvider實(shí)現(xiàn)了WebFluxTagsProvider接口,它返回了method、uri、exception、status、outcome這幾個(gè)tag
spring-boot-actuator-2.1.5.RELEASE-sources.jar!/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java
public final class WebFluxTags { private static final Tag URI_NOT_FOUND = Tag.of("uri", "NOT_FOUND"); private static final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION"); private static final Tag URI_ROOT = Tag.of("uri", "root"); private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN"); private static final Tag EXCEPTION_NONE = Tag.of("exception", "None"); private static final Tag OUTCOME_UNKNOWN = Tag.of("outcome", "UNKNOWN"); private static final Tag OUTCOME_INFORMATIONAL = Tag.of("outcome", "INFORMATIONAL"); private static final Tag OUTCOME_SUCCESS = Tag.of("outcome", "SUCCESS"); private static final Tag OUTCOME_REDIRECTION = Tag.of("outcome", "REDIRECTION"); private static final Tag OUTCOME_CLIENT_ERROR = Tag.of("outcome", "CLIENT_ERROR"); private static final Tag OUTCOME_SERVER_ERROR = Tag.of("outcome", "SERVER_ERROR"); private WebFluxTags() { } public static Tag method(ServerWebExchange exchange) { return Tag.of("method", exchange.getRequest().getMethodValue()); } public static Tag status(ServerWebExchange exchange) { HttpStatus status = exchange.getResponse().getStatusCode(); if (status == null) { status = HttpStatus.OK; } return Tag.of("status", String.valueOf(status.value())); } public static Tag uri(ServerWebExchange exchange) { PathPattern pathPattern = exchange .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pathPattern != null) { return Tag.of("uri", pathPattern.getPatternString()); } HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null) { if (status.is3xxRedirection()) { return URI_REDIRECTION; } if (status == HttpStatus.NOT_FOUND) { return URI_NOT_FOUND; } } String path = getPathInfo(exchange); if (path.isEmpty()) { return URI_ROOT; } return URI_UNKNOWN; } private static String getPathInfo(ServerWebExchange exchange) { String path = exchange.getRequest().getPath().value(); String uri = StringUtils.hasText(path) ? path : "/"; return uri.replaceAll("//+", "/").replaceAll("/$", ""); } public static Tag exception(Throwable exception) { if (exception != null) { String simpleName = exception.getClass().getSimpleName(); return Tag.of("exception", StringUtils.hasText(simpleName) ? simpleName : exception.getClass().getName()); } return EXCEPTION_NONE; } public static Tag outcome(ServerWebExchange exchange) { HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null) { if (status.is1xxInformational()) { return OUTCOME_INFORMATIONAL; } if (status.is2xxSuccessful()) { return OUTCOME_SUCCESS; } if (status.is3xxRedirection()) { return OUTCOME_REDIRECTION; } if (status.is4xxClientError()) { return OUTCOME_CLIENT_ERROR; } return OUTCOME_SERVER_ERROR; } return OUTCOME_UNKNOWN; } }
WebFluxTags定義了URI_NOT_FOUND、URI_REDIRECTION、URI_ROOT、URI_UNKNOWN、EXCEPTION_NONE、OUTCOME_UNKNOWN、OUTCOME_INFORMATIONAL、OUTCOME_SUCCESS、OUTCOME_REDIRECTION、OUTCOME_CLIENT_ERROR、OUTCOME_SERVER_ERROR這些Tag常量
WebFluxTagsProvider接口定義了httpRequestTags方法;DefaultWebFluxTagsProvider實(shí)現(xiàn)了WebFluxTagsProvider接口,它返回了method、uri、exception、status、outcome這幾個(gè)tag;WebFluxTags定義了URI_NOT_FOUND、URI_REDIRECTION、URI_ROOT、URI_UNKNOWN、EXCEPTION_NONE、OUTCOME_UNKNOWN、OUTCOME_INFORMATIONAL、OUTCOME_SUCCESS、OUTCOME_REDIRECTION、OUTCOME_CLIENT_ERROR、OUTCOME_SERVER_ERROR這些Tag常量
到此,關(guān)于“spring boot中WebFluxTagsProvider的作用是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
分享標(biāo)題:springboot中WebFluxTagsProvider的作用是什么
標(biāo)題網(wǎng)址:http://jinyejixie.com/article26/gggocg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、App設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)