-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added exponential delay for poisoned message handlers (#175)
* added exponential delay for poisoned message handlers
- Loading branch information
1 parent
b88bfe4
commit 4408887
Showing
9 changed files
with
97 additions
and
43 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
core/src/main/scala/com/avast/clients/rabbitmq/ExponentialDelay.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.avast.clients.rabbitmq | ||
|
||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration.{Duration, FiniteDuration} | ||
|
||
class ExponentialDelay(val initialDelay: Duration, val period: Duration, val factor: Double, val maxLength: Duration) { | ||
private val maxMillis = maxLength.toMillis | ||
|
||
def getExponentialDelay(attempt: Int): FiniteDuration = { | ||
if (attempt == 0) FiniteDuration(initialDelay._1, initialDelay._2) | ||
else { | ||
val millis = math.min( | ||
maxMillis, | ||
(period.toMillis * math.pow(factor, attempt - 1)).toLong | ||
) | ||
FiniteDuration(millis, TimeUnit.MILLISECONDS) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters