How does Akka HTTP manage timeouts for different situations, such as request timeouts and connection timeouts? How can you handle long-lived or streaming connections?
Akka HTTP manages timeouts using various configurations. For request timeouts, it uses akka.http.server.request-timeout
setting, which defines the maximum duration a request can take before being automatically rejected. Connection timeouts are managed by akka.http.client.connecting-timeout
, determining how long to wait for establishing a connection.
For long-lived or streaming connections, Akka HTTP provides support through its reactive streams implementation. To handle these connections, you can use Source
and Sink
components from Akka Streams API, allowing backpressure control and efficient resource management. Additionally, you can disable request timeout for specific routes using withoutRequestTimeout
directive or increase idle timeout settings (akka.http.[server/client].idle-timeout
) to accommodate longer durations.