Spring Cloud Netflix: Whats happening in ZuulConfiguration with the ZuulServlet?

旧时模样 提交于 2019-12-13 02:09:44

问题


Looking in ZuulConfiguration, I see the following:

@Bean
public ZuulController zuulController() {
    return new ZuulController();
}

@Bean
public ServletRegistrationBean zuulServlet() {
    return new ServletRegistrationBean(new ZuulServlet(),
            this.zuulProperties.getServletPattern());
}   

ZuulController wraps the ZuulServlet and manages its lifecycle as if it were a Spring Controller. What throws me is that the ZuulConfiguration class registers the servlet anyways using a ServletRegistrationBean. Perhaps I am thinking the wrong thing, but I would think that you would do one or the other. Could someone explain why both are necessary?

Using this configuration, is the ZuulServlet running as a true servlet (known by the embedded servlet container), a controller (which delegates to the servlet) or both?

Thanks,

Joshua


回答1:


From this commit:

Allow streaming of multipart requests in Zuul proxy

It turns out that the suckiness of Zuul with multipart requests comes almost entirely from the Multipart handling in Spring's DispatcherServlet. This change makes the proxy routes available on an alternative path /zuul/ (where /zuul is the default value of zuul.servletPath). I have tested those with 800MB file uploads using the main method in the FormZuulServletProxyApplicationTests and the main observation is that there is no OutOfMemory error (no-one tries to download the complete request body). It works with Ribbon and with the simple (HttpClient) filter. With Ribbon you will need to set some timeouts if you want to upload files as large as that, e.g. see application.yml in the tests:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
ribbon:
  ConnectTimeout: 3000
  ReadTimeout: 60000

You need to set "Transfer-Encoding: chunked" in the incoming request. Chrome does not do this by default apparently, but I was able to test with curl, e.g.

$ curl -v -H "Transfer-Encoding: chunked" \
  -F "file=@mylarg.iso" \
  localhost:9999/zuul/direct/file

The old proxy paths through the DispatcherServlet are still available (for backwards compatibility and for convenience of having the paths available at the root of the context path).



来源:https://stackoverflow.com/questions/32084831/spring-cloud-netflix-whats-happening-in-zuulconfiguration-with-the-zuulservlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!