Does Dropwizard Support Servlet 3 Asynchronous Servlets?

走远了吗. 提交于 2019-12-06 05:55:55

问题


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



来源:https://stackoverflow.com/questions/12089834/does-dropwizard-support-servlet-3-asynchronous-servlets

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