SpringCloud
ZUUL
SpringCloud路由网关zuul包含了对请求的路由和过滤两个最主要的功能。其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础,而过滤器功能则负责对请求的处理过程进行干预,是实现请求校验、服务聚合等功能的基础。ZUUL和Eureka进行整合,将zuul自身注册为eureka服务治理下的应用,同时从eureka中获得其他微服务的消息,也即以后的访问微服务都是通过zuul跳转后获得。
新建一个模块microcloudservice-zuul-gateway-9527。
在项目中添加zuul和eureka相关依赖包。
修改项目的yml配置文件。server: port: 9527 eureka: client: service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ instance: instance-id: gateway-9501.com prefer-ip-address: true info: app.name: gwolf-microcloudservice-zuul-gateway-9527 company.name: www.gwolf.com build.artifactId: $project.artifactId$ build.version: $project.version$ spring: application: name: microcloudservice-zuul-gateway
增加微服务启动主类:package com.gwolf.springcloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.zuul.EnableZuulProxy;@SpringBootApplication@EnableZuulProxypublic class Zuul_9527_StartSpringCloudApplication { public static void main(String[] args) { SpringApplication.run(Zuul_9527_StartSpringCloudApplication.class,args); }}
现在我们查看是否能够通过zuul路由网关访问到我们的微服务。http://gateway-9501.com:9527/microcloudservice-provider-dept/dept/list