# spring-cloud-trip-zuul **Repository Path**: iherr/spring-cloud-trip-zuul ## Basic Information - **Project Name**: spring-cloud-trip-zuul - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-10-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 一、API网关 API Gateway是一个服务器,也可以说是进入系统的唯一节点。这跟面向对象设计模式中的Facade模式很像。API Gateway封装内部系统的架构,并且提供API给各个客户端。它还可能有其他功能,如授权、监控、负载均衡、缓存、请求分片和管理、静态响应处理等。下图展示了一个适应当前架构的API Gateway。 ###二、 项目基础配置 为实现API网关,需要几个基础的module,请参考上一节实战(3)。配置不变。 * eureka-server,作为eureka的server服务注册中心 * service-provider-1,eureka-client端,连接到eureka-server成为服务提供者1。 ### 四、Zuul项目配置 > 1、pom.xml依赖 ``` org.springframework.cloud spring-cloud-starter-netflix-zuul org.springframework.cloud spring-cloud-starter-netflix-eureka-client ``` 2、启动类中,增加注解@EnableZuulProxy激活zuul。该注解整合了@EnableCircuitBreaker、@EnableDiscoveryClient,是个组合注解。 3、yml配置中,项目的spring.application.name为service-eureka-zuul,端口8040。 ```xml server: port: 8040 spring: application: name: service-eureka-zuul eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ instance: prefer-ip-address: true management: endpoints: web: exposure: include: '*' endpoint: health: show-details: always ``` 5、测试 需要先依次启动项目基础配置中的2个module(eureka-server和service-provider-1)。才能启动zuul项目。 * 访问http://localhost:8001/1 会返回service1。代表原有service-provider-1项目启动成功。 * 访问http://localhost:8040/service-provider/1 也同样会返回service1。代表zuul项目启动成功。 * 访问http://localhost:8761 可以看到1个SERVICE-PROVIDER和1个SERVICE-EUREKA-ZUUL。