Does Dropwizard Support Servlet 3 Asynchronous Servlets?

你说的曾经没有我的故事 提交于 2019-12-04 12:54:25

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.

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

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