多语言展示
当前在线:1219今日阅读:27今日分享:41

SpringCloud路由网关ZUUL介绍以及实现基本配置

SpringCloud路由网关ZUUL介绍如何实现基本配置
工具/原料
1

SpringCloud

2

ZUUL

方法/步骤
1

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

2

新建一个模块microcloudservice-zuul-gateway-9527。

3

在项目中添加zuul和eureka相关依赖包。            microservicecloud        com.gwolf.springcloud        1.0-SNAPSHOT        4.0.0    com.gwolf.springcloud    microcloudservice-zuul-gateway-9527    microcloudservice-zuul-gateway-9527    http://www.example.com            UTF-8        1.8        1.8                            org.springframework.cloud            spring-cloud-starter-zuul                            org.springframework.cloud            spring-cloud-starter-eureka                            org.springframework.cloud            spring-cloud-starter-config                                    org.springframework            springloaded                            org.springframework.boot            spring-boot-devtools                           

4

修改项目的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

5

增加微服务启动主类: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);    }}

6

现在我们查看是否能够通过zuul路由网关访问到我们的微服务。http://gateway-9501.com:9527/microcloudservice-provider-dept/dept/list

推荐信息