Reconnection Policies for Ruby SDK
In networked applications, maintaining a stable connection is critical. The PubNub Ruby Software Development Kit (SDK) controls reconnection with two parameters to help applications recover from temporary network disruptions.
Default behavior
Default behavior: If you do not set custom values, :reconnect_interval
and :reconnect_attempts
default to 10
.
Types of reconnection policies
Pubnub Ruby SDK uses two parameters in reconnection logic: :reconnect_interval
(in seconds) and :reconnect_attempts
. They are set when initializing a Pubnub::Client
instance. By default, their values are 10
and 10
.
When the connection is lost, the server logs the warning "Connection lost! Reason: reasons," announces status to subscribers with type Pubnub::Constants::TIMEOUT_ANNOUNCEMENT
(:disconnect
), waits :reconnect_interval
, and tries to reconnect. When reconnected, the client announces to subscribers status type Pubnub::Constants::RECONNECTED_ANNOUNCEMENT
(:reconnected
).
- Use when: Increase
:reconnect_attempts
for transient outages; decrease:reconnect_interval
for faster retries in reliable networks.