Zuul不将请求转发到其他微服务 [英] Zuul not forwarding requests to other micro-services
问题描述
我正在使用Spring Boot微服务.我已经配置了eureka,zuul代理和另一个微服务(帐户).如果我直接从帐户致电,那可以正常工作.帐户和zuul服务器都显示在eureka上.
I am using spring boot micro-services. I have configured eureka, zuul proxy and another microservice(account). If I am calling from account directly it is working fine. account and zuul server both showing on eureka.
当我尝试使用zuul代理进行搜索时,它正在获取状态代码200OK
,但未获得任何结果
When I try to hit using zuul proxy it is getting status code 200OK
but not getting any result
以下是我对zuul的配置
Below is my configuration for 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
route matched=ZuulRoute{id='account', path='/account/**', serviceId='ACCOUNT', url='http://192.168.0.62:8081/', stripPrefix=false, retryable=null, sensitiveHeaders=[], customSensitiveHeaders=false, } --------------------------- Mapped to 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": "*"
}
如果发生问题,我无法从这里得到任何东西,请检查并告知我.任何帮助都会有用
I am unable to get anything from here if something is mising, Kindly check and do let me know. any help will be useful
谢谢.
如果需要更多信息,请告诉我.
If needed more info let me know.
推荐答案
正如我所看到的,您设置了Eureka,但未正确使用它.首先,您拥有zuul yaml
As I can see, you set up Eureka but you're not using it correctly. First in zuul yaml you have
eureka:
client:
registerWithEureka: true
您不需要在eureka上注册zuul应用程序,因为您是直接访问zuul网关,所以没有人会尝试找到并访问您的网关.
you don't need to register your zuul application with eureka, because you are accessing zuul gateway directly, no one service will try to locate and reach your gateway.
然后
account:
serviceId: ACCOUNT
url: http://192.168.0.62:8081/
stripPrefix: false
predicate:
- Path=/accounts/**
如果您有服务发现,则不需要url
属性和predicate: - Path
,请尝试:
if you have service discovery you don't need url
property and predicate: - Path
, try:
account:
serviceId: <YOUR_ACCOUNT_SERVICE_ID>
stripPrefix: false
path: /account/**
默认情况下,serviceId为:
by default serviceId is:
spring:
application:
name: <YOUR_ACCOUNT_SERVICE_ID>
在此处
这篇关于Zuul不将请求转发到其他微服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!