Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bdd6d9d
Configure backoffs from application settings
reactivestudio Nov 8, 2026
b4a3312
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 8, 2026
3362251
Depend on the Spring module of backoff
reactivestudio Nov 8, 2026
db030e6
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 8, 2026
18ac90d
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
aad15d7
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
8dc40fe
Register backoffs through registrars in the auto-configuration
reactivestudio Nov 9, 2026
1473225
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
c6172a6
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
1bdab69
Register backoff beans after every registrar
reactivestudio Nov 9, 2026
9885960
Customize the backoff registry through beans
reactivestudio Nov 9, 2026
fd5ced3
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
1ca8bce
Cover backoff beans replacing the settings
reactivestudio Nov 9, 2026
d4fee59
Apply settings and beans through the standard customizer
reactivestudio Nov 9, 2026
59a8b4d
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
e6faefb
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
2b662e5
Use the default backoff name in the auto-configuration tests
reactivestudio Nov 9, 2026
520c952
Fill the backoff registry in the auto-configuration
reactivestudio Nov 9, 2026
8d74ef0
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
93dd9a4
Name the validation of the default backoff
reactivestudio Nov 9, 2026
6ad4632
Pick backoff algorithms from factory beans in the auto-configuration
reactivestudio Nov 9, 2026
740c103
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
251d17e
Say that the name of the default backoff is reserved
reactivestudio Nov 9, 2026
c6c4e0b
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 9, 2026
e2b5d5e
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
4817c16
Fill the backoff registry through the properties registrar
reactivestudio Nov 10, 2026
9c24cbd
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
8e92384
Bind backoff settings by the key of their type in the auto-configuration
reactivestudio Nov 10, 2026
421e221
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
25b077d
Put the misspelled field under its type in the auto-configuration test
reactivestudio Nov 10, 2026
3ef32e7
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
1dd0b7f
Describe relaxed backoff names in the settings guide
reactivestudio Nov 10, 2026
c91d1cc
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
78d0fb9
Wrap the start failures paragraph of the settings guide
reactivestudio Nov 10, 2026
935a788
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
238d2c1
Name the backoff factory beans of the auto-configuration by their type
reactivestudio Nov 10, 2026
bd771ef
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
2237a7a
Bind backoff settings through properties in the auto-configuration
reactivestudio Nov 10, 2026
0f3999c
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
1ba224f
Merge branch 'resilience-backoff-spring-boot' into resilience-backoff…
reactivestudio Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Customize the backoff registry through beans
  • Loading branch information
reactivestudio committed Nov 9, 2026
commit 98859607ecd952f193381ccb54c2b7fef9f417a2
10 changes: 6 additions & 4 deletions architecture/pattern/resilience/backoff/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ registry.default
With nothing set, the `default` block has the values shown above, and `delay` is `1s`; `jitter: 0` turns the
jitter off. An instance takes the fields it leaves out from `default`, including `type`. Any `Backoff` bean is
available by its bean name and replaces the settings of an instance with that name; a bean named `default`
replaces the default block. To add backoffs from code, declare a `BackoffRegistrar` bean.
replaces the default block. To change the registry from code, declare a `BackoffRegistryCustomizer` bean: it gets
the filled registry, settings and beans alike, and may go through `names`, `register` and `replace`.
Customizers run in `@Order`.

Wrong settings stop the application at start, with the name of the instance, even when a bean replaces it:
an unknown field or type, a value the `Backoff` being built refuses, a field of an instance that its type does not use, such
as `delay` on an exponential one, and an instance named `default`. The `default` block may hold the fields of
both types, since instances of either inherit them.
an unknown field or type, a value the `Backoff` being built refuses, a field of an instance that its type does
not use, such as `delay` on an exponential one, and an instance named `default`. The `default` block may hold
the fields of both types, since instances of either inherit them.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config

import org.springframework.beans.factory.ListableBeanFactory
import org.springframework.beans.factory.ObjectProvider
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import pro.vlprojects.semantic.resilience.backoff.Backoff
import pro.vlprojects.semantic.resilience.backoff.spring.boot.BackoffRegistry
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.properties.BackoffConfigurationProperties

@AutoConfiguration
@EnableConfigurationProperties(BackoffConfigurationProperties::class)
public class BackoffAutoConfiguration {

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public fun backoffPropertiesRegistrar(properties: BackoffConfigurationProperties): BackoffRegistrar =
BackoffPropertiesRegistrar(properties)

@Bean
@ConditionalOnMissingBean
public fun backoffRegistry(
registrars: ObjectProvider<BackoffRegistrar>,
beanFactory: ListableBeanFactory,
): BackoffRegistry = BackoffRegistry()
properties: BackoffConfigurationProperties,
backoffs: Map<String, Backoff>,
customizers: ObjectProvider<BackoffRegistryCustomizer>,
): BackoffRegistry = BackoffPropertiesMapper(properties)
.asBackoffs()
.plus(backoffs)
.let(::BackoffRegistry)
.also { registry ->
registrars
customizers
.orderedStream()
.forEach { registrar -> registrar.register(registry) }
.forEach { customizer -> customizer.customize(registry) }
}
.also(BackoffBeansRegistrar(beanFactory)::register)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pro.vlprojects.semantic.resilience.backoff.spring.boot.config

import pro.vlprojects.semantic.resilience.backoff.spring.boot.BackoffRegistry

public fun interface BackoffRegistryCustomizer {

public fun customize(registry: BackoffRegistry)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex
import org.springframework.boot.test.context.runner.ApplicationContextRunner
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.annotation.Order
import pro.vlprojects.semantic.resilience.backoff.Backoff
import pro.vlprojects.semantic.resilience.backoff.FixedBackoff
import pro.vlprojects.semantic.resilience.backoff.spring.boot.BackoffRegistry
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.BackoffAutoConfiguration
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.BackoffRegistrar
import pro.vlprojects.semantic.resilience.backoff.spring.boot.config.BackoffRegistryCustomizer
import java.time.Duration

class BackoffAutoConfigurationTests {
Expand Down Expand Up @@ -79,14 +80,46 @@ class BackoffAutoConfigurationTests {
}

@Test
fun `an own registrar adds to the registry`() {
fun `a customizer adds to the registry`() {
runner
.withUserConfiguration(OwnRegistrarConfiguration::class.java)
.withUserConfiguration(AddingCustomizerConfiguration::class.java)
.run { context ->
assertEquals(Duration.ofSeconds(9), context.getRegistry()["orders"].calculate(1))
}
}

@Test
fun `a customizer sees the settings and the backoff beans`() {
runner
.withUserConfiguration(
PaymentsBackoffConfiguration::class.java,
ReplacingCustomizerConfiguration::class.java,
)
.withPropertyValues("$PREFIX.instances.orders.initial-delay=1ms")
.run { context ->
val registry = context.getRegistry()

assertEquals(setOf("default", "orders", "payments"), registry.names)
assertTrue(registry.names.all { name -> registry[name].calculate(1) == CUSTOMIZED_DELAY })
}
}

@Test
fun `customizers run in their order`() {
runner
.withUserConfiguration(OrderedCustomizersConfiguration::class.java)
.run { context ->
assertEquals(Duration.ofSeconds(2), context.getRegistry().default.calculate(1))
}
}

@Test
fun `a backoff bean that needs the registry stops the start`() {
runner
.withUserConfiguration(CircularBackoffConfiguration::class.java)
.run { context -> assertNotNull(context.startupFailure) }
}

@Test
fun `an unknown field stops the start`() {
runner
Expand Down Expand Up @@ -129,16 +162,49 @@ class BackoffAutoConfigurationTests {
}

@Configuration(proxyBeanMethods = false)
class OwnRegistrarConfiguration {
class AddingCustomizerConfiguration {

@Bean
fun ownRegistrar() = BackoffRegistrar { registry ->
fun addingCustomizer() = BackoffRegistryCustomizer { registry ->
registry.register("orders", FixedBackoff.ofSeconds(9))
}
}

@Configuration(proxyBeanMethods = false)
class ReplacingCustomizerConfiguration {

@Bean
fun replacingCustomizer() = BackoffRegistryCustomizer { registry ->
registry.names.forEach { name -> registry.replace(name, FixedBackoff.of(CUSTOMIZED_DELAY)) }
}
}

@Configuration(proxyBeanMethods = false)
class OrderedCustomizersConfiguration {

@Bean
@Order(2)
fun lastCustomizer() = BackoffRegistryCustomizer { registry ->
registry.replace(BackoffRegistry.DEFAULT_NAME, FixedBackoff.ofSeconds(2))
}

@Bean
@Order(1)
fun firstCustomizer() = BackoffRegistryCustomizer { registry ->
registry.replace(BackoffRegistry.DEFAULT_NAME, FixedBackoff.ofSeconds(1))
}
}

@Configuration(proxyBeanMethods = false)
class CircularBackoffConfiguration {

@Bean
fun payments(registry: BackoffRegistry): Backoff = registry.default
}

private companion object {

const val PREFIX = "semantic.resilience.backoff"
val CUSTOMIZED_DELAY: Duration = Duration.ofSeconds(3)
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.