sim*_*bro 0 spring-boot netflix-eureka netflix-zuul
通过阅读各种书籍/教程,似乎可以在将Zuul与Eureka服务发现结合使用时自动配置Zuul中的路由。这意味着我不必显式添加到Zull的application.properties的路由。
所以我理解正确吗?还是我仍然需要显式添加路由到Zuul才能使其充当网关?
我希望它根据在Eureka中注册的应用程序名称自动创建路由。这可能吗?
(注意:我实际上已经尝试过了,但是当我转到http:// localhost:8762 / routes时,我只会看到一个错误页面。)
小智 5
当然。在大多数微服务实现中,内部微服务端点不会暴露在外部。一组公共服务将使用API网关向客户端公开。
zuul代理内部使用Eureka服务器进行服务发现。
- 我希望它根据在Eureka中注册的应用程序名称自动创建路由。这可能吗?
当然。我将向您展示网关示例。
1.创建您的服务项目(用户服务)
创建application.properties文件
# --- Spring Config
spring:
application:
name: OVND-USER-SERVICE
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
Run Code Online (Sandbox Code Playgroud)
2.设置Zuul项目(网关服务)
1. @ EnableZuulproxy告诉Spring Boot这是一个Zuul代理
@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class GatewayServiceApplication {
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
尤里卡网站(localhost:8761)
| 归档时间: |
|
| 查看次数: |
1346 次 |
| 最近记录: |