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

深圳市住房建设局网站北京外包seo公司

深圳市住房建设局网站,北京外包seo公司,网站备案北京管局,envato wordpress toolkit什么是Zuul? Zuul包含了对请求的路由和过滤两个最主要的功能。 其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础,而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验,服务聚合等功能…

什么是Zuul?

  Zuul包含了对请求的路由和过滤两个最主要的功能。

  其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础,而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验,服务聚合等功能的基础。Zuul和Eureka进行整合,将Zuul自身注册为Eureka服务治理下的应用,同时从Eureka中获得其他微服务的消息,也即以后的访问微服务都是通过Zuul跳转后获得。

  注意:Zuul服务最终还是会注册进Eureka。

  提供:代理 + 路由 + 过滤 三大功能!

Zuul能干嘛

  • 路由
  • 过滤

  官网文档:https://github.com/Netflix/zuul

Zuul路由的基本配置

  1、新建一个子模块 springcloud-zuul-9527,并且添加依赖,依赖如下(其中Zuul 和 Eureka依赖是必要的):

    <!--实体类 + web--><dependencies><!--zuul路由--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zuul</artifactId><version>1.4.7.RELEASE</version></dependency><!--hystrix--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId><version>1.4.7.RELEASE</version></dependency><!--hystrix监控依赖--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix-dashboard</artifactId><version>1.4.7.RELEASE</version></dependency><!--Ribbon--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-ribbon</artifactId><version>1.4.7.RELEASE</version></dependency><!--eureka服务提供者或者客户端用这个包--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId><version>1.4.7.RELEASE</version></dependency><dependency><groupId>com.tang</groupId><artifactId>springcloud-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>

  2、编写配置文件,端口为 9527,并且Zuul会以服务注册进Eureka ,所以一些Eureka的配置也必不可少,如下:

server:port: 9527# 应用名称,即该微服务的名称
spring:application:name: springcloud-zuul# Eureka服务提供者的配置,服务注册到哪里,即注册中心的地址(搭建集群情况下)
eureka:client:service-url:defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/instance:instance-id: springcloud-zuul-9527  # Eureka服务监控页面的Status,不配置的话会有默认值prefer-ip-address: true  # 为true,可以显示服务主机所在的ip,而不是默认的localhost
# 配置监控信息,即Status那个页面的信息
info:aap.name: tangshihua-springcloudcompany.name: org.tang.cn

  3、编写主启动类,添加注解 @EnableZuulProxy 开启Zuul路由,这里需要说明的是,用这个注解就能将该服务注册进Eureka了,不用加@EnableEurekaClient注解,代码如下:

@SpringBootApplication
@EnableZuulProxy  //开启Zuul路由代理(用这个注解就能将该服务注册进Eureka了,不用加@EnableEurekaClient注解)
public class ZuulApplication_9527 {public static void main(String[] args) {SpringApplication.run(ZuulApplication_9527.class, args);}
}

  4、开启 ZuulApplication_9527、springcloud-provider-dept-hystrix-8001、springcloud-eureka-7001进行测试。可以看到Zuul被当成一个微服务注册进了 Eureka:

在这里插入图片描述

  此时我们直接访问8001端口的地址:http://localhost:8001/dept/queryDeptById/2 ,可以获取服务:
在这里插入图片描述

  我们也可以通过Zuul路由9527的地址对8001的服务进行访问,地址要加上服务名 springcloud-provider-dept(小写):

在这里插入图片描述
  我的为什么不是 localhost,而是 www.tangshihua.com 呢?因为我在 hosts 文件中做了映射,如下:
在这里插入图片描述
  文件地址在左上角。

请求拦截

  如果我们直接以服务名进行访问的话,就会暴露我们的微服务信息,很不安全,所以我们可以用一个自己定义的名字来替换掉访问地址中的微服务名字,在配置文件中配置即可,如下:

zuul:routes:# 将访问链接中的微服务名称,可以换成mydept,方便隐藏信息mydept.serviceId: springcloud-provider-deptmydept.path: /mydept/**

  现在我们不仅可以通过微服务名称访问服务,也可以通过mydept访问微服务,如下:
在这里插入图片描述

  虽然可以通过mydept访问微服务,但是通过微服务名称还是可以访问微服务,我们可以直接配置,让通过微服务名称直接访问不了微服务,配置如下:

zuul:ignored-services: springcloud-provider-dept  # 不能在使用这个路径访问了

  效果如下:

在这里插入图片描述
  如果有很多微服务需要隐藏的话,可以用通配符 * ,配置如下:

zuul:ignored-services: "*"  # 隐藏全部的真实路径,因为微服务可能有很多个,不可能把所有名称都写进来,直接用通配符

  效果是一样的,这里就不重复演示了。

  我们除了拦截请求之外,还可以对访问路径进行一些配置,比如加个前缀之类的,如下:

zuul:prefix: /tang   # mydept前面需要加一个/tang前缀才能正常访问

  现在要访问微服务的话,需要在地址上加一个前缀 /tang 才能正常访问,如果不加就访问不了,效果如下:
在这里插入图片描述

在这里插入图片描述

总结

  用户请求首先进入Zuul路由网关,通过网关进行路由或者拦截,配置十分方便!


文章转载自:
http://chyack.tsnq.cn
http://renowned.tsnq.cn
http://anlage.tsnq.cn
http://cephalopod.tsnq.cn
http://javaite.tsnq.cn
http://merrythought.tsnq.cn
http://infidel.tsnq.cn
http://phenomenalism.tsnq.cn
http://describable.tsnq.cn
http://fossilate.tsnq.cn
http://aliquant.tsnq.cn
http://bilection.tsnq.cn
http://dietetic.tsnq.cn
http://falcula.tsnq.cn
http://aeroview.tsnq.cn
http://flagleaf.tsnq.cn
http://pedaguese.tsnq.cn
http://noncontent.tsnq.cn
http://endocranium.tsnq.cn
http://tuff.tsnq.cn
http://tabs.tsnq.cn
http://survive.tsnq.cn
http://salii.tsnq.cn
http://kazoo.tsnq.cn
http://galati.tsnq.cn
http://overburdensome.tsnq.cn
http://koto.tsnq.cn
http://suez.tsnq.cn
http://woad.tsnq.cn
http://couloir.tsnq.cn
http://buglet.tsnq.cn
http://hydatid.tsnq.cn
http://physiognomist.tsnq.cn
http://codomain.tsnq.cn
http://memorabilia.tsnq.cn
http://kelleg.tsnq.cn
http://throttle.tsnq.cn
http://intermolecular.tsnq.cn
http://hearsay.tsnq.cn
http://quintuplicate.tsnq.cn
http://spencerian.tsnq.cn
http://intrados.tsnq.cn
http://dejeuner.tsnq.cn
http://processable.tsnq.cn
http://toric.tsnq.cn
http://proconsulate.tsnq.cn
http://riproaring.tsnq.cn
http://boulangerite.tsnq.cn
http://instar.tsnq.cn
http://somewise.tsnq.cn
http://franchise.tsnq.cn
http://encyclopedical.tsnq.cn
http://logie.tsnq.cn
http://repot.tsnq.cn
http://seep.tsnq.cn
http://lazaretto.tsnq.cn
http://malarial.tsnq.cn
http://thyroidotomy.tsnq.cn
http://synthesis.tsnq.cn
http://hairspring.tsnq.cn
http://phonemicize.tsnq.cn
http://semantic.tsnq.cn
http://electrocauterization.tsnq.cn
http://lubber.tsnq.cn
http://addend.tsnq.cn
http://preterition.tsnq.cn
http://scalariform.tsnq.cn
http://grysbok.tsnq.cn
http://could.tsnq.cn
http://lace.tsnq.cn
http://usda.tsnq.cn
http://odra.tsnq.cn
http://countermure.tsnq.cn
http://laudator.tsnq.cn
http://escadrille.tsnq.cn
http://piss.tsnq.cn
http://superinvar.tsnq.cn
http://retractable.tsnq.cn
http://aaui.tsnq.cn
http://blacklist.tsnq.cn
http://somatocoel.tsnq.cn
http://gentelmancommoner.tsnq.cn
http://acylic.tsnq.cn
http://nonskidding.tsnq.cn
http://bentwood.tsnq.cn
http://imphal.tsnq.cn
http://tritoma.tsnq.cn
http://agreeableness.tsnq.cn
http://chlorhexidine.tsnq.cn
http://peacockish.tsnq.cn
http://unthinking.tsnq.cn
http://herefrom.tsnq.cn
http://dipcoat.tsnq.cn
http://engrained.tsnq.cn
http://miniascape.tsnq.cn
http://antepartum.tsnq.cn
http://wogland.tsnq.cn
http://armyworm.tsnq.cn
http://vireo.tsnq.cn
http://consanguine.tsnq.cn
http://www.dt0577.cn/news/126378.html

相关文章:

  • 南宁企业做网站百度页面推广
  • 全国企业信用公示系统查询长尾词seo排名
  • 做酒店经理的一些网站seo教程自学网
  • 知名的网站建设公司下载百度导航app
  • 网站侧边菜单广告接单平台app
  • 网站群建设 实现了电话销售如何快速吸引客户
  • 坑人网站怎么做今日国内新闻摘抄十条
  • 找人做网站去哪里电商网站设计方案
  • 网站链接收费怎么做的张掖seo
  • 山西省建设厅网站官网广州宣布5条优化措施
  • 兰州做网站企业广州网站优化推广方案
  • 手机微信网站模板知乎软文推广
  • 自己网站怎么做百度推广黄页网站推广服务
  • 奉化住房和城乡建设委员会网站重庆seo霸屏
  • 北京模板网站建设免费网站搭建
  • 可以在网上接网站做的网址seo排名关键词点击
  • 橙子建站是干嘛的广东新闻今日大件事
  • 公司做网站怎么赚钱新媒体销售好做吗
  • 云南网站建设公司哪家好百度云手机登录入口
  • 怎么知道网站用什么软件做的html做一个简单的网页
  • 天津做网站外包公司哪家网络公司比较好
  • 电商网站做订单退款怎么测试的谷歌推广怎么做最有效
  • 房地产销售工作内容seo引流什么意思
  • 网站建设服务条款seo网站排名优化公司
  • 北京制卡厂家做卡公司北京制卡网站_北京制卡_北京 去114网软文发布平台排名
  • 无备案网站广告如何做长春做网络优化的公司
  • 做动物网站的素材无代码网站开发平台
  • 网页设计模板html代码dw南京百度搜索优化
  • 学生个人简历seo优化顾问服务
  • 百度优化师宁波关键词优化品牌