flybonzai
flybonzai

Reputation: 3941

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?

Upvotes: 0

Views: 1060

Answers (1)

LiorH
LiorH

Reputation: 18824

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)

Upvotes: 1

Related Questions