Zuul的主要功能是路由转发和过滤器。路由功能是微服务的一部分,比如/api/user转发到到user服务,/api/shop转发到到shop服务。zuul默认和Ribbon结合实现了负载均衡的功能, 类似于nginx转发。
zuul相当于一个微服务需要注册到Eurka中
@EnableEurekaClient @EnableZuulProxy @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
application.yml配置
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8888/eureka/
server:
port: 8769
spring:
application:
name: service-zuul
zuul:
routes:
api-a:
path: /api-member/**
service-id: service-member
api-b:
path: /api-order/**
service-id: service-order
发送请求http://127.0.0.1:8769/api-member/getMemberAll
转发到http://127.0.0.1:8762/getMemberAll
注意:很重要 在启动类的上方 开启网关 @EnableZuulProxy