Skip to content

Keeping a connection active using an Heartbeat AtmosphereInterceptor

Thomas Ferris Nicolaisen edited this page Apr 1, 2015 · 6 revisions

Available in 1.1.0/2.0 only.

Proxies and firewalls can sometimes close inactive connections. To prevent them from closing a connection when using streaming, server side events or websocket transport, you can install an heartbeat AtmosphereInterceptor that will write whitespace after 60 seconds of inactivity, keeping the connection active. For that, just add in you web/application.xml

   // application.xml
   <applicationConfig>
      <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
      <param-value>org.atmosphere.interceptor.HeartbeatInterceptor</param-value>
   </applicationConfig>

   // web.xml
   <init-param>
      <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
      <param-value>org.atmosphere.interceptor.HeartbeatInterceptor</param-value>
   </init-param>

To reduce or increase the interval (default is 60 seconds), just add

   // application.xml
   <applicationConfig>
      <param-name>org.atmosphere.interceptor.HeartbeatInterceptor.heartbeatFrequencyInSeconds</param-name>
      <param-value>value</param-value>
   </applicationConfig>

   // web.xml
   <init-param>
      <param-name>org.atmosphere.interceptor.HeartbeatInterceptor.heartbeatFrequencyInSeconds</param-name>
      <param-value>value</param-value>
   </init-param>

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally