Why are duplicate event listeners/consumers supported?
See original GitHub issueHi @RobWin,
As per this Javadoc, the Circuit breaker registry will either create a new circuit breaker or return an existing one with the same name. At the same time, I also noticed that the event listeners use an implementation of a List to keep track of all the registered event listeners.
Due to the dual behavior of Circuit Breaker registry, clients would now have to make sure that they don’t attach duplicate listeners.
Use-case: If I’d like to attach an onEvent
listener at the time of creation of circuit breaker, I risk registering the same listener multiple times.
Is there a reason to allow duplicate listeners? If this is not intended, we could use CopeOnWriteArraySet
if we don’t expect the # of listeners to be large. But if it’s expected to have a large # of listeners, one option would be to use ConcurrentHashMap
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Yes right. You can consume
EntryAddedEvent<CircuitBreaker>
.I think what I’m asking for is possible for Circuit Breaker Registry events, but not for Circuit Breaker instance events.
https://github.com/resilience4j/resilience4j/blob/2222e3e80ea6a4b58fe8e5b024aae03530e08ffe/resilience4j-circuitbreaker/src/main/java/io/github/resilience4j/circuitbreaker/CircuitBreakerRegistry.java#L71-L74