首次调用ZuulException(SendErrorFilter) [英] ZuulException (SendErrorFilter) at first call

查看:1281
本文介绍了首次调用ZuulException(SendErrorFilter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Spring Cloud,Spring Boot和Docker构建应用程序.整个应用程序运行正常.我有几个微服务.每个项目都在Docker上运行.当我尝试通过Zuul API网关使用微服务时,第一次调用时出现错误.但是,如果我刷新浏览器,它就可以正常工作.错误在下面给出-

I am building an application by Spring Cloud ,Spring Boot and Docker. Entire application is working fine. I have couple of micro-services. Each of the project is running on Docker. When I try to consume my micro-services through Zuul API Gateway I am getting an error for the 1st call. But if I refresh the browser it's working fine. The error is given below--

2019-03-10 04:54:55.440  WARN [netflix- 
zuul-api-gateway- 
server,1855093598d4f99c,1855093598d4f99c
true] 1 --- [nio-8765-exec-1] 
o.s.c.n.z.filters.post.SendErrorFilter   
: Error during filtering


com.netflix.zuul.exception.ZuulException 
at 
org.springframework.cloud.netflix.zuul.
filters.post.SendErrorFilter.
findZuulException(SendErrorFilter.java:
114) ~[spring-cloud-netflix-zuul- 
2.1.0.RC3.jar!/:2.1.0.RC3]
at 
org.springframework.cloud.netflix.zuul.
filters.post.SendErrorFilter.run
(SendErrorFilter.java:76) ~[spring- 
cloud- 
netflix-zuul-2.1.0.RC3.jar!/
:2.1.0.RC3]
at 
com.netflix.zuul.ZuulFilter.runFilter
(ZuulFilter.java:117) [zuul-core- 
1.3.1.jar!/:1.3.1]
at 
com.netflix.zuul.FilterProcessor.
processZuulFilter(FilterProcessor.
java:193) [zuul-core-1.3.1.jar!/:1.3.1]
 at 
com.netflix.zuul.FilterProcessor.
runFilters(FilterProcessor.java:157) 
[zuul-core-1.3.1.jar!/:1.3.1]
at 
com.netflix.zuul.FilterProcessor.error
(FilterProcessor.java:105) [zuul-core- 
1.3.1.jar!/:1.3.1]
at com.netflix.zuul.ZuulRunner.error
(ZuulRunner.java:112) [zuul-core- 
1.3.1.jar!/:1.3.1]
at 
com.netflix.zuul.http.ZuulServlet.error
(ZuulServlet.java:145) [zuul-core- 
1.3.1.jar!/:1.3.1]
at 
com.netflix.zuul.http.ZuulServlet.servic
e(ZuulServlet.java:83) [zuul-core- 
1.3.1.jar!/:1.3.1]
at org.springframework.web.servlet.mvc.
Servlet 
letWrappingController.java:165) [spring- 
webmvc- 
5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.spr

我已经为所有项目创建了图像.并将其推送到DockerHub中. Docker-Compose文件也将其推送到GitHub中.下面是路径.

I have already created the images for all my projects. And push it in the DockerHub. And the Docker-Compose file I also push it in the GitHub. Below is the path.

https://github.com/numery009/DockerCompose/blob /master/docker-compose.yaml

我还将其部署在EC2的Docker Swarm上. 但是,当我尝试通过Zuul使用微服务时,它根本无法工作.而且我的每个请求都收到相同的过滤器错误".

I also deploy it on the Docker Swarm on EC2. But When I try to consume my micro-services through Zuul it's not working at all. And I am getting the same "Filter Error" for my every request.

请帮助!!

推荐答案

对于请求,我们需要保留3件事,这些事情要经过Zuul

There should be 3 things we need to keep on the top of our head for the request which are gone through the Zuul

1)根据本文档- Zuul内部使用Ribbon来调用远程URL,默认情况下,Spring Cloud在第一次调用时会懒惰地加载Ribbon客户端.可以使用以下配置为Zuul更改此行为,这将导致在应用程序启动时紧急加载与子Ribbon相关的应用程序上下文.

Zuul internally uses Ribbon for calling the remote url’s and Ribbon clients are by default lazily loaded up by Spring Cloud on first call. This behavior can be changed for Zuul using the following configuration and will result in the child Ribbon related Application contexts being eagerly loaded up at application startup time.

application.yaml

application.yaml

zuul:
   ribbon:
      eager-load:
         enabled: true

application.properties

application.properties

zuul.ribbon.eager-load.enabled= true

2)根据本文档- 服务发现配置- 如果Zuul使用服务发现,则需要考虑两个超时:Hystrix超时(因为默认情况下所有路由都包装在Hystrix命令中)和Ribbon超时. Hystrix超时需要考虑功能区读取和连接超时以及该服务将发生的重试总数.默认情况下,除非明确指定Hystrix超时,否则Spring Cloud Zuul会尽力为您计算Hystrix超时.

Service Discovery Configuration --- If Zuul is using service discovery there are two timeouts you need to be concerned with, the Hystrix timeout (since all routes are wrapped in Hystrix commands by default) and the Ribbon timeout. The Hystrix timeout needs to take into account the Ribbon read and connect timeout PLUS the total number of retries that will happen for that service. By default Spring Cloud Zuul will do its best to calculate the Hystrix timeout for you UNLESS you specify the Hystrix timeout explicitly.

Hystrix超时使用以下公式计算:

The Hystrix timeout is calculated using the following formula:

(ribbon.ConnectTimeout + ribbon.ReadTimeout) * (ribbon.MaxAutoRetries + 1) * 
(ribbon.MaxAutoRetriesNextServer + 1)

作为示例,如果您在应用程序属性中设置以下属性

As an example, if you set the following properties in your application properties

application.yaml

application.yaml

ribbon:
   ReadTimeout:100
   ConnectTimeout:500
   MaxAutoRetries:1
   MaxAutoRetriesNextServer:1

application.properties

application.properties

ribbon.ReadTimeout= 100
ribbon.ConnectTimeout= 500
ribbon.MaxAutoRetries= 1
ribbon.MaxAutoRetriesNextServer= 1

然后将Hystrix超时(在这种情况下为所有路由)设置为2400ms.

Then the Hystrix timeout (for all routes in this case) will be set to 2400ms.

在我的zuul应用程序配置中,我添加了以下属性.它正在为我的第一个电话工作,没有任何错误.

In my zuul application config I have added the following properties. And it's working for my 1st call with out any error.

application.yaml

application.yaml

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 11000

ribbon:
   ConnectTimeout: 10000
   ReadTimeout: 10000

application.properties

application.properties

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds= 11000

ribbon.ConnectTimeout= 10000
ribbon.ReadTimeout: 10000

3)这是最简单的方法.禁用hystrix执行超时.

3) This is the most easiest way. Disable the hystrix execution time out.

根据本文档- https://github.com/Netflix/Hystrix/wiki/Configuration#executiontimeoutenabled

以下属性将禁用Zuul上的hystrix执行超时

Following property will disable the hystrix execution time out on Zuul

application.properties

application.properties

hystrix.command.default.execution.timeout.enabled=false

如果我们牢记这三种情况,则可以轻松获得ZuulException(SendErrorFilter)的解决方案.

If we keep remember these 3 scenarios then we can easily get the solution of ZuulException (SendErrorFilter).

这篇关于首次调用ZuulException(SendErrorFilter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆