简体   繁体   中英

How to keep a long-running HTTP connection alive in Dropwizard/Jersey?

I have a simple rest endpoint that is searching for a message in a Kafka topic. Depending on when/if this message is found, this process could take a couple minutes. When I call this endpoint via Swagger I end up receiving a 504 - Server Timeout back. How can I keep this connection alive so the client doesn't receive a timeout?

Dropwizard will let you configure the idleTimeout (defaults to 30 seconds), see configuration reference

But I must warn you this is a dangerous path with issues like:

  1. Draining the connection pool
  2. Network issues that will terminate the connections
  3. Middlewares (like load balancers) that will terminate the connections

If your process needs more time then there are some solutions like: 1. Websockets (notify the client when the operation completed) 2. Long polling (periodically poll the server for completion result)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM