Does Dropwizard support Servlet 3 asynchronous servlets? If not, is it on the roadmap at any time in the near future?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It uses Jetty 8, which supports Servlet 3.0. Jersey (and JAX-RS) doesn't have any support for this, but it's forthcoming in JAX-RS 2.0 (and Jersey 2.0). Dropwizard doesn't add anything special, but when Jersey 2.0 ships, the next major Dropwizard release will very likely include it.
回答2:
You can use https://github.com/jetty-project/jetty-eventsource-servlet. Read wiki for how to impl Servlet and EventSource
In your DW Service implementation you add your SSE servlet
environment.addServlet(new MySseEventSourceServlet(), "/sse"); Then add this to your DW config
http: connectorType: NONBLOCKING now you can start listening for Server-sent Event's on
<host>:<port>/sse ex.
curl localhost:8080/sse -H"Accept: text/event-stream" See working example @ GitHub, https://github.com/andershedstrom/dropwizard-with-sse