You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow configuring and enabling exponential backoff for failing
connections, instead of relying on reconnections in regular intervals.
Exponential backoff can be configured in order to lighten server load if
multiple clients are reconnecting.
The new configuration parameter is called `exponentialBackoff` and
requires two parameters `backoffRate` and `backoffLimit`.
* @param {boolean} param0.reconnectAutomatically - An optional boolean flag to indicate whether to reconnect automatically when a websocket connection is severed
97
103
* @param {number} param0.retryProcessTimePeriod - An optional number for how long the time period between retrying to send a messgae to a WebSocket server should be
98
104
* @param {boolean|number} param0.retryConnectionDelay - An optional parameter for whether to delay WebSocket reconnection attempts by a time period. If true, the delay is 1000ms, otherwise it is the number passed. The default value when this parameter is undefined will be interpreted as 1000ms.
105
+
* @param {ExponentialBackoffParams} param0.exponentialBackoff - An optional containing configuration for exponential backoff. If this parameter is undefined, exponential backoff is disabled. The minimum delay is determined by retryConnectionDelay. If retryConnectionDelay is set is false, this setting will not be in effect.
99
106
* @param {string} param0.storageType - An optional string specifying the type of storage to use for persisting messages in the message queue
100
107
* @param {string} param0.storageKey - An optional string specifying the key used to store the messages data against in sessionStorage/localStorage
101
108
* @returns {object} The class instance
@@ -109,6 +116,7 @@ export default class Sarus {
109
116
retryProcessTimePeriod?: number;
110
117
reconnectAutomatically?: boolean;
111
118
retryConnectionDelay: number;
119
+
exponentialBackoff?: ExponentialBackoffParams;
112
120
storageType: string;
113
121
storageKey: string;
114
122
@@ -164,6 +172,7 @@ export default class Sarus {
164
172
reconnectAutomatically,
165
173
retryProcessTimePeriod,// TODO - write a test case to check this
166
174
retryConnectionDelay,
175
+
exponentialBackoff,
167
176
storageType ="memory",
168
177
storageKey ="sarus",
169
178
}=props;
@@ -208,6 +217,13 @@ export default class Sarus {
208
217
? undefined
209
218
: retryConnectionDelay)??1000;
210
219
220
+
/*
221
+
When a exponential backoff parameter object is provided, reconnection
222
+
attemptions will be increasingly delayed by an exponential factor.
223
+
This feature is disabled by default.
224
+
*/
225
+
this.exponentialBackoff=exponentialBackoff;
226
+
211
227
/*
212
228
Sets the storage type for the messages in the message queue. By default
213
229
it is an in-memory option, but can also be set as 'session' for
0 commit comments