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

做暧暧暖网站欧美seo自学

做暧暧暖网站欧美,seo自学,企业名录登记,长沙疫情确诊最新消息概述 Spring Cloud Netflix zuul组件是微服务架构中的网关组件,Zuul作为统一网关,是所有访问该平台的请求入口,核心功能是路由和过滤。 目前公司业务就是基于Zuul搭建的网关服务,且提供的服务包括转发请求(路由)、黑名单IP访问拦截、URL资源访问时的权限拦截、统一访问日志记…

概述

Spring Cloud Netflix zuul组件是微服务架构中的网关组件,Zuul作为统一网关,是所有访问该平台的请求入口,核心功能是路由和过滤

目前公司业务就是基于Zuul搭建的网关服务,且提供的服务包括转发请求(路由)、黑名单IP访问拦截、URL资源访问时的权限拦截、统一访问日志记录/异常处理/单点登录引导功能本文主要内容:Zuul的执行流程、Zuul过滤实现、Zuul安全配置、Zuul路由配置、Zuul集成Hystrix、Zuul集成Zipkin与Sleuth

Zuul项目实战

Zuul执行流程

  • 接收请求
    • 客户端发送请求到Zuul服务器(前置经过Nginx反向代理)
  • Pre-filters
    • 请求首先通过Pre类型的过滤器,这些过滤器可以进行安全检查、身份验证、日志记录、选择路由等操作。
  • 路由转发Routing
    • 如果Pre-filter通过请求将被路由到具体的微服务实例上。Zuul 可以根据配置的路由规则将请求转发到不同的后端服务。
  • 服务调用
    • Zuul通过Fegin进行客户端负载均衡,选择一个服务实例进行调用
  • Post-filters
    • 服务处理完成后,响应会返回并经过 Post 类型的过滤器,这些过滤器可以修改返回的响应头、收集统计信息等。最终Zuul将响应发送回客户端
  • Error-filters
    • 如果在任何阶段发生错误,请求将被转发到 Error 类型的过滤器,进行错误处理后经过Post-filters,最终Zuul将响应发送回客户端

Zuul过滤器

网关过滤器
pre-filter

前置过滤器在请求被路由到源服务器之前执行,通常继承ZuulFilter抽象类。实际项目中我们使用前置过滤器对于400到500的状态错误码进行过滤,进而对于从cas认证服务中获取token的特定请求进行错误日志的记录

package test.gateway.filter;import org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException;
import test.common.util.R;
import com.google.gson.Gson;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;/*** @Description: 捕获400到500错误码,否则不执行该过滤器*/
public class ErrorStatusCodeZuulFilter extends ZuulFilter {protected static String GET_TOKEN_URI =  "/cas/getToken";@Overridepublic String filterType() {return "post";}@Overridepublic int filterOrder() {return -1; // Needs to run before SendResponseFilter which has filterOrder == 0}@Overridepublic boolean shouldFilter() {    		int statusCode = Integer.parseInt(RequestContext.getCurrentContext().get("responseStatusCode").toString());return statusCode >= 400 && statusCode <= 500;}@Overridepublic Object run() {RequestContext ctx = RequestContext.getCurrentContext();int statusCode = Integer.parseInt( ctx.get("responseStatusCode").toString());	String uri = ctx.get("requestURI").toString();if (uri != null && uri.equals(GET_TOKEN_URI)) { //获取token请求失败R<String>  res = new R<>();		res.setCode(statusCode);res.setData(null);res.setMsg("Account or password error");ctx.setResponseBody(new Gson().toJson(res));return null;}try {throw new Exception();} catch (Throwable t) {	    		throw new ZuulRuntimeException(new ZuulException(t, statusCode, t.getMessage()));}}
}
routing-filter

处理将请求发送到源服务器的逻辑

post-filter

后置过滤器在请求被路由后执行,可以对响应进行修改或添加额外的HTTP等。

error-filter

当请求处理过程中发生错误时,这些过滤器会被调用,同时最终也会调用后置post类型过滤器返回 

扩展-OncePerRequestFilter

OncePerRequestFilter是Spring Framework中的一个接口,它属于Servlet过滤器(Filter)的范畴,但不是Zuul中定义的特定过滤器类型。在Spring MVC中,OncePerRequestFilter确保每个请求只被处理一次。它通过同步代码块来保证,即使在支持异步处理的 Spring MVC 应用程序中,请求也不会被重复处理。项目中我们通过自定义过滤器(继承OncePerRequestFilter)处理访问公共接口且未携带token的请求,该过滤器也属于前置的过滤器,因为它通常用于在请求进入其他阶段之前执行某些操作。

Zuul安全配置

自定义WebSecurityConfig

在Spring Security的上下文中,WebSecurityConfig类通常用于配置Spring Security的安全策略。此类继承自WebSecurityConfigurerAdapter,WebSecurityConfig可以用来定义Zuul网关的安全设置,通过提供了一种自定义安全配置的方法实现,实际项目中我们对zuul进行的http请求相关安全配置

package test.zuul.config;
import .../*** @Description: Zuul http configuration*/
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { // 定义Zuul网关的安全设置private final static Logger logger = LoggerFactory.getLogger(WebSecurityConfig.class);@Autowiredprivate FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;@Autowiredprivate FindByIndexNameSessionRepository<? extends Session> sessionRepository;@Autowiredprivate RedisOperationsSessionRepository redisOperationsSessionRepository; @Autowiredprivate AuthenticationServiceFeign authenticationService;@Overridepublic void configure(HttpSecurity http) throws Exception {http.csrf().disable(); //禁用csrfhttp.headers().frameOptions().disable();ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry =http.antMatcher("/**") // 允许所有请求.authorizeRequests();filterIgnorePropertiesConfig.getUrls().forEach(url -> registry.antMatchers(url).permitAll());registry.anyRequest().authenticated();http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login/idpbg"))	        .and().logout().logoutUrl("/logout").addLogoutHandler(new LogoutHandler() { //登出后处理逻辑@Overridepublic void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {					if(authentication != null) {String indexName = authentication.getName();// 查询用户的 Session 信息      Map<String, ? extends Session> userSessions = sessionRepository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, indexName);// 删除当前用户相关sessionList<String> sessionIds = new ArrayList<>(userSessions.keySet());for (String session : sessionIds) {redisOperationsSessionRepository.deleteById(session);}//删除系统当前在线用户信息...}Cookie cookie = new Cookie();//重置cookie...response.addCookie(cookie);}}).logoutSuccessHandler(logoutSuccessHandler()).oauth2Login().and().oauth2Client();	}private LogoutSuccessHandler logoutSuccessHandler() { //登出成功后处理逻辑return new LogoutSuccessHandler() {@Overridepublic void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)throws IOException, ServletException {if(authentication != null) {if(authentication.getDetails() instanceof OAuth2AuthenticationDetails) {// 刪除JWT......}}new SecurityContextLogoutHandler().logout(request, null, null);try {response.sendRedirect("/"); //重定向到登录页面}} catch (IOException e) {e.printStackTrace();}}};}
}

Zuul-路由规则

  # 默认情况下所有的eureka上的服务都会被zuul自动地创建映射关系来进行路由,# 设置ignored-services: '*' 时,避免注册到Eureka中的服务被Zuul默认路由,从而避免不必要的服务暴露ignored-services: '*' routes:# CAS 路由配置cas-server:sensitiveHeaders: path: /cas/**serviceId: cas-serverstrip-prefix: false #表示Zuul不会移除请求的URI路径前面的/cas/部分# END CAS路由配置..其他服务路由配置..

Zuul-熔断

在项目开发Zuul服务时,通常会集成Hystrix,并通过HystrixH对依赖的微服务进行熔断保护,防止单个服务的故障影响到整个系统

hystrix:command:default:execution:isolation:thread:# hystrix超时时间计算方法 = ribbonTimeout(ReadTimeout + ConnectTimeout) * (maxAutoRetries + 1) * (maxAutoRetriesNextServer + 1)#  timeoutInMilliseconds = (600000 + 600000) * 1 * 2timeoutInMilliseconds: 2400000# 仅正式局配置Threadpool参数threadpool:default:coreSize: 50maximumSize: 10000allowMaximumSizeToDivergeFromCoreSize: truemaxQueueSize: -1ribbon:  # Zuul 如果使用 Eureka查找路由,则需要配置ConnectTimeout和SocketTimeoutConnectTimeout: 600000 # 6min,由于通过网关存在下载/导报表服务,此类需求建立连接耗时比较长,所以设置为6minSocketTimeout: 600000 # 6min,由于通过网关存在下载/导报表服务,此类需求建立连接耗时比较长,所以设置为6minReadTimeout: 600000  # 6min,由于通过网关存在下载/导报表服务,此类需求建立连接耗时比较长,所以设置为6minMaxAutoRetries: 0MaxAutoRetriesNextServer: 1 #下一个服务调用自动重试次数MaxTotalConnections: 400  # okhttp模式下最大连接数量eureka:enabled: true #通过Eureka路由到具体微服务httpclient:enabled: falseokhttp:  #use okhttp will betterenabled: truefeign: httpclinet: #use okhttp will betterenabled: falseokhttp: enabled: true 

Zuul-Zipkin与Sleuth

Sleuth是Spring Cloud的一个组件,用于在微服务架构中提供分布式跟踪解决方案。Sleuth通常与Zipkin等分布式跟踪系统配合使用,可以生成请求链路的跟踪信息,帮助开发者理解请求在系统中流动的路径,从而优化性能和定位问题,项目中我们在application.yml文件配置:

 zipkin:#base-url: http://10.169.33.369/  # Zipkin Server URL, 仅当spring.zipkin.sender.type=web才需要设置,基于消息服务则不需要设置enabled: true # 启用Zipkin,默认truesender:type: rabbit  #  微服務基于消息服务发送 Zipkin Data到Zipkin Serverrabbitmq:queue: zipkin  # 对应RabbitMq的队列名,仅当spring.zipkin.sender.type=rabbit时有效,默认配置为zipkinsleuth:web:client:enabled: true  # 对于web请求,是否开启sleuth功能。默认为true。sampler:probability: 0.1 # 1.0即100%收集 默认0.1


文章转载自:
http://dinncoariot.stkw.cn
http://dinncosergeancy.stkw.cn
http://dinncovalor.stkw.cn
http://dinncosclerocorneal.stkw.cn
http://dinncospiegeleisen.stkw.cn
http://dinncounlessened.stkw.cn
http://dinncoflorescent.stkw.cn
http://dinncospeechifier.stkw.cn
http://dinncoexcursively.stkw.cn
http://dinncopipewort.stkw.cn
http://dinncokinsman.stkw.cn
http://dinncosocket.stkw.cn
http://dinncoerom.stkw.cn
http://dinncosportswoman.stkw.cn
http://dinnconerine.stkw.cn
http://dinncolibelous.stkw.cn
http://dinnconeighborly.stkw.cn
http://dinncocounselee.stkw.cn
http://dinncocomplementizer.stkw.cn
http://dinncobehavioristic.stkw.cn
http://dinncoejaculate.stkw.cn
http://dinncocanalise.stkw.cn
http://dinncoajaccio.stkw.cn
http://dinncowhittuesday.stkw.cn
http://dinncosyncopal.stkw.cn
http://dinncofollicular.stkw.cn
http://dinncointake.stkw.cn
http://dinncobetelnut.stkw.cn
http://dinncoatop.stkw.cn
http://dinncocroaker.stkw.cn
http://dinncoautonomy.stkw.cn
http://dinncoexodontia.stkw.cn
http://dinncooctose.stkw.cn
http://dinncounseriousness.stkw.cn
http://dinncokloof.stkw.cn
http://dinnconautilus.stkw.cn
http://dinncosnowbreak.stkw.cn
http://dinncokirlian.stkw.cn
http://dinncoladderman.stkw.cn
http://dinncocandu.stkw.cn
http://dinncodragonhead.stkw.cn
http://dinncolokoum.stkw.cn
http://dinncounbeloved.stkw.cn
http://dinncoinstallant.stkw.cn
http://dinncorye.stkw.cn
http://dinncodragway.stkw.cn
http://dinncowhangarei.stkw.cn
http://dinncocajun.stkw.cn
http://dinncopyroxylin.stkw.cn
http://dinncowithdrawn.stkw.cn
http://dinncokerchief.stkw.cn
http://dinncosauch.stkw.cn
http://dinncoxenobiotic.stkw.cn
http://dinncogab.stkw.cn
http://dinncopetto.stkw.cn
http://dinncounfrequented.stkw.cn
http://dinncolippy.stkw.cn
http://dinncoinfamize.stkw.cn
http://dinncotalkie.stkw.cn
http://dinncoparable.stkw.cn
http://dinncomsbc.stkw.cn
http://dinncopukras.stkw.cn
http://dinncodiatonicism.stkw.cn
http://dinncochalcocite.stkw.cn
http://dinncogalgenhumor.stkw.cn
http://dinncoreversible.stkw.cn
http://dinncodiazomethane.stkw.cn
http://dinncohabakkuk.stkw.cn
http://dinncoseoul.stkw.cn
http://dinncoallahabad.stkw.cn
http://dinncowizzled.stkw.cn
http://dinncoscummy.stkw.cn
http://dinncospectre.stkw.cn
http://dinncoagenesis.stkw.cn
http://dinncouncinaria.stkw.cn
http://dinncoaddress.stkw.cn
http://dinncotuyere.stkw.cn
http://dinncohorrid.stkw.cn
http://dinncoseparatum.stkw.cn
http://dinncocadwallader.stkw.cn
http://dinncoautoinoculation.stkw.cn
http://dinncoorthicon.stkw.cn
http://dinncotarpeian.stkw.cn
http://dinnconira.stkw.cn
http://dinncourinoir.stkw.cn
http://dinncoprosoma.stkw.cn
http://dinncodulocracy.stkw.cn
http://dinncoeolic.stkw.cn
http://dinncoqr.stkw.cn
http://dinncothirteenth.stkw.cn
http://dinncoanal.stkw.cn
http://dinncoliterate.stkw.cn
http://dinnconeuroglia.stkw.cn
http://dinncoadscititious.stkw.cn
http://dinncoradc.stkw.cn
http://dinncovitally.stkw.cn
http://dinncoamphithecium.stkw.cn
http://dinncopassively.stkw.cn
http://dinncosubtilise.stkw.cn
http://dinncodrubbing.stkw.cn
http://www.dinnco.com/news/73247.html

相关文章:

  • 企业做网站的必要性百度网站介绍
  • 关于政府网站改版建设的请示抖音seo培训
  • dedecms本地打开网站电商运营基础知识
  • 手机网站如何做优化seo免费优化工具
  • 建站 网站程序经济新闻最新消息财经
  • 网站经营许可备案号百度关键词收费标准
  • 找做网站的朋友蜜雪冰城推广软文
  • 做推广哪个网站最热门seo排名优化培训怎样
  • 某颜值女主播低俗内容流出视频seo搜索引擎优化书籍
  • 衡阳南华疫情最新消息怎么优化电脑系统
  • 手机版网站做一下多少钱如何做seo搜索优化
  • 个人网站备案的好处微信怎么引流营销呢
  • 建设银行网站怎么查开户行郑州疫情最新情况
  • 网站打开慢的解决方法seo发包软件
  • 六安建设机械网站百度关键词热搜
  • 门户网站功能清单腾讯营销平台
  • 做盗版系统网站会不会alexa排名
  • 台州做网站seo百度seo排名优化排行
  • 专业做互联网招聘的网站有哪些内容网站备案是什么意思
  • 长春网长春网站建设络推广北京网站建设专业公司
  • 分析网站的外链seo是什么意思 seo是什么职位
  • 网站建设.龙兵网站上不去首页seo要怎么办
  • 网站建设设计设计公司哪家好今日国内新闻最新消息大事
  • 教做布艺的网站亚马逊alexa
  • 社交网站开发 转发站长工具网站
  • 建行的官方网站吗抖音搜索关键词排名
  • 青海省城乡建设信息官官方网站网络营销的特点包括
  • 外贸网站建设内容包括哪些百度关键词seo优化
  • 午夜做网站最新清远发布
  • 集团网站建营销是什么