Spring boot 使用Zuul和Eureka自动配置路由
通过阅读各种书籍/教程,在将Zuul与Eureka service discovery结合使用时,似乎可以在Zuul中自动配置路由。这意味着我不必显式地向Zuul的application.properties添加路由 所以我理解正确了?或者我仍然需要向Zuul显式添加路由,以便它作为网关工作 我想让它自动创建路由,从应用程序名称的,是注册与Eureka。这可能吗Spring boot 使用Zuul和Eureka自动配置路由,spring-boot,netflix-zuul,netflix-eureka,Spring Boot,Netflix Zuul,Netflix Eureka,通过阅读各种书籍/教程,在将Zuul与Eureka service discovery结合使用时,似乎可以在Zuul中自动配置路由。这意味着我不必显式地向Zuul的application.properties添加路由 所以我理解正确了?或者我仍然需要向Zuul显式添加路由,以便它作为网关工作 我想让它自动创建路由,从应用程序名称的,是注册与Eureka。这可能吗 (注意:我实际上已经尝试过了,但是当我转到时,我只得到了一个错误页面。)是的。您可以将Zuul与Eureka集成,并根据在Eureka
(注意:我实际上已经尝试过了,但是当我转到时,我只得到了一个错误页面。)是的。您可以将Zuul与Eureka集成,并根据在Eureka中注册的应用程序名称配置路由。只需将以下配置添加到Zuul应用程序:
zuul:
ignoredServices: "*"
routes:
a-service: /a-service/**
b-service: /b-service/**
c-service: /c-service/**
d-service: /d-service/**
对。您可以将Zuul与Eureka集成,并根据在Eureka中注册的应用程序名称配置路由。只需将以下配置添加到Zuul应用程序:
zuul:
ignoredServices: "*"
routes:
a-service: /a-service/**
b-service: /b-service/**
c-service: /c-service/**
d-service: /d-service/**
当然。在大多数微服务实现中,内部微服务端点不会暴露在外部。将使用API网关向客户端公开一组公共服务 zuul代理在内部使用Eureka服务器进行服务发现
# --- Spring Config
spring:
application:
name: OVND-USER-SERVICE
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
2。建立Zuul项目(网关服务)
1.@EnableZuulproxy告诉Spring Boot这是一个Zuul代理
@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class GatewayServiceApplication {
2.创建application.properties文件
# =======================================
# Gateway-service Server Configuration
# =======================================
# --- Spring Config
spring:
application:
name: gateway-service
server:
port: ${PORT:8080}
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
zuul:
host:
routes:
## By default, all requests to user service for example will start with: "/user/"
## What will be sent to the user service is what comes after the path defined,
## So, if request is "/user/v1/user/tedkim", user service will get "/v1/user/tedkim".
user-service:
path: /user/**
service-id: OVND-USER-SERVICE
another-service:
path: /another/**
service-id: OVND-ANOTHER-SERVICE
Eureka网站(本地主机:8761)
当然可以。在大多数微服务实现中,内部微服务端点不会暴露在外部。将使用API网关向客户端公开一组公共服务 zuul代理在内部使用Eureka服务器进行服务发现
# --- Spring Config
spring:
application:
name: OVND-USER-SERVICE
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
2。建立Zuul项目(网关服务)
1.@EnableZuulproxy告诉Spring Boot这是一个Zuul代理
@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class GatewayServiceApplication {
2.创建application.properties文件
# =======================================
# Gateway-service Server Configuration
# =======================================
# --- Spring Config
spring:
application:
name: gateway-service
server:
port: ${PORT:8080}
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
zuul:
host:
routes:
## By default, all requests to user service for example will start with: "/user/"
## What will be sent to the user service is what comes after the path defined,
## So, if request is "/user/v1/user/tedkim", user service will get "/v1/user/tedkim".
user-service:
path: /user/**
service-id: OVND-USER-SERVICE
another-service:
path: /another/**
service-id: OVND-ANOTHER-SERVICE
Eureka网站(本地主机:8761)
还有一件事:我的设置实际上在工作——唯一的一件事是Zuul实例的“/routes”端点不工作。事实证明,它已更新为“/exactor/routes”,需要通过在application.properties.com.exposure.include=*”中添加“management.endpoints.web.exposure=*”来激活它。另外,我只使用了Eureka,而不必向Zuul添加任何路由配置。所有Eureka客户端应用程序将显示在Zuul的“/执行器/路线”中。是。也许这个网站对你有帮助。是的,这正是我遇到的问题。我建议任何找到这篇文章的人,如果他们有同样的问题,请点击你发布的Github文章中的链接。它很好地解释了这个问题,以及如何解决它。再次感谢Ted。还有一件事:我的设置实际上正在工作——唯一的一件事是Zuul实例的“/routes”端点没有工作。事实证明,它已更新为“/exactor/routes”,需要通过在application.properties.com.exposure.include=*”中添加“management.endpoints.web.exposure=*”来激活它。另外,我只使用了Eureka,而不必向Zuul添加任何路由配置。所有Eureka客户端应用程序将显示在Zuul的“/执行器/路线”中。是。也许这个网站对你有帮助。是的,这正是我遇到的问题。我建议任何找到这篇文章的人,如果他们有同样的问题,请点击你发布的Github文章中的链接。它很好地解释了这个问题,以及如何解决它。再次感谢泰德。