This is an automated email from the ASF dual-hosted git repository.
michaelpearce pushed a commit to branch 2.0.x
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git
The following commit(s) were added to refs/heads/2.0.x by this push:
new cfba9ba AMQNET-722 Updated config doc, and little update to random
delay time
new 43299ed Merge pull request #76 from lukeabsent/AMQNET-722
cfba9ba is described below
commit cfba9ba74d31ef0eb2b4831460e4436d8e3909c7
Author: lukeabsent <[email protected]>
AuthorDate: Thu Sep 2 23:49:55 2021 +0200
AMQNET-722 Updated config doc, and little update to random delay time
---
docs/configuration.md | 1 +
src/NMS.AMQP/Provider/Failover/FailoverProvider.cs | 13 ++++++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/docs/configuration.md b/docs/configuration.md
index 3375d45..8d0dd17 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -66,5 +66,6 @@ The complete set of configuration options for failover is
listed below:
- **failover.maxReconnectDelay** The maximum time that the client will wait
before attempting a reconnect. This value is only used when the backoff feature
is enabled to ensure that the delay doesn't not grow too large. Defaults to 30
seconds as the max time between connect attempts.
- **failover.useReconnectBackOff** Controls whether the time between
reconnection attempts should grow based on a configured multiplier. This option
defaults to true.
- **failover.reconnectBackOffMultiplier** The multiplier used to grow the
reconnection delay value, defaults to 2.0d.
+- **failover.reconnectDelayRandomFactor** Reconnect backoff random factor. 0
means no randomisation. 0.5 would mean backoff time could be (pseudo)randomly
between 0.5 and 1.5 of normal reconnect backoff time. 1 would mean backoff time
could be between 0 and 2x normal reconnect backoff. 2 would mean backoff time
between 0 and 3x normal backoff, and so on. Default value is 0.
- **failover.maxReconnectAttempts** The number of reconnection attempts
allowed before reporting the connection as failed to the client. The default is
no limit or (-1).
- **failover.startupMaxReconnectAttempts** For a client that has never
connected to a remote peer before this option control how many attempts are
made to connect before reporting the connection as failed. The default is to
use the value of maxReconnectAttempts.
\ No newline at end of file
diff --git a/src/NMS.AMQP/Provider/Failover/FailoverProvider.cs
b/src/NMS.AMQP/Provider/Failover/FailoverProvider.cs
index 25f6529..faebe3e 100644
--- a/src/NMS.AMQP/Provider/Failover/FailoverProvider.cs
+++ b/src/NMS.AMQP/Provider/Failover/FailoverProvider.cs
@@ -674,12 +674,19 @@ namespace Apache.NMS.AMQP.Provider.Failover
}
}
- long randomFactor = (long) ((1 - 2 * random.NextDouble()) *
-
failoverProvider.ReconnectDelayRandomFactor * nextReconnectDelay);
+ long randomFactor = (long)((1 - 2 * GetRandomDouble()) *
failoverProvider.ReconnectDelayRandomFactor * nextReconnectDelay);
- return Math.Min(failoverProvider.MaxReconnectDelay,
nextReconnectDelay + randomFactor);
+ return Math.Max(0,
Math.Min(failoverProvider.MaxReconnectDelay, nextReconnectDelay +
randomFactor));
}
+ private double GetRandomDouble()
+ {
+ lock (random) // Random is not thread safe
+ {
+ return random.NextDouble();
+ }
+ }
+
public long RecordNextAttempt()
{
return ++reconnectAttempts;