我正在使用Spring Boot微服务。我已经配置了eureka,zuul代理和另一个微服务(帐户)。如果我直接从帐户致电,那可以正常工作。帐户和zuul服务器都显示在eureka上。
当我尝试使用zuul代理进行搜索时,它正在获取状态代码200OK
,但未得到任何结果
以下是我对zuul的配置
server:
port: 8076
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8078/eureka/
instance:
hostname: localhost
health-check-url-path: /actuator/health
status-page-url-path: /actuator/info
logging:
level:
com.netflix.discovery: 'ON'
org.springframework.cloud: DEBUG
zuul:
ignoredServices: '*'
routes:
account:
serviceId: ACCOUNT
url: http://192.168.0.62:8081/
stripPrefix: false
predicate:
- Path=/accounts/**
debug:
requests: true
management:
security:
enabled: false
endpoints:
web:
exposure:
include: '*'
到目前为止的控制台日志
route match = ZuulRoute {id ='account',path ='/ account / **', serviceId ='ACCOUNT',url ='http://192.168.0.62:8081/', stripPrefix = false,retryable = null,sensitiveHeaders = [], customSensitiveHeaders = false,} ---------------------------映射到org.springframework.cloud.netflix.zuul.web.ZuulController@7bb67520
"zuul.ignoredServices": {
"value": "*"
},
"zuul.routes.account.serviceId": {
"value": "ACCOUNT"
},
"zuul.routes.account.url": {
"value": "http://192.168.0.62:8081/"
},
"zuul.routes.account.stripPrefix": {
"value": false
},
"zuul.routes.account.predicate[0]": {
"value": "Path=/accounts/**"
},
"zuul.debug.requests": {
"value": true
},
"management.security.enabled": {
"value": false
},
"management.endpoints.web.exposure.include": {
"value": "*"
}
如果有什么问题,我无法从这里得到任何东西,请检查并告知我。任何帮助都会有用
谢谢。
如果需要更多信息,请告诉我。
答案 0 :(得分:0)
如我所见,您设置了Eureka,但使用不正确。首先是zuul yaml
eureka:
client:
registerWithEureka: true
您不需要在eureka上注册zuul应用程序,因为您是直接访问zuul网关,因此没有任何服务会尝试找到并访问您的网关。
比
account:
serviceId: ACCOUNT
url: http://192.168.0.62:8081/
stripPrefix: false
predicate:
- Path=/accounts/**
如果您有服务发现请求,则不需要url
属性和predicate: - Path
,请尝试:
account:
serviceId: <YOUR_ACCOUNT_SERVICE_ID>
stripPrefix: false
path: /account/**
默认情况下,serviceId为:
spring:
application:
name: <YOUR_ACCOUNT_SERVICE_ID>
从here中查看我的答案