How to implement a CacheRegistryStore for CircuitBreaker with MemCached
See original GitHub issueResilience4j version: 1.7.1
Java version: 17.0.2
Spring Boot version: 2.7.5
Hello, I’m trying to create a CacheRegistryStore for a CB with MemCached. I implemented CacheRegistryStore but when I tried to run the application it threw an exception which indicated that the CB could not be serialized.
Is there a way to serialize the circuit breaker to store it? @Romeh @RobWin The exception generated is the following:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloController': Unsatisfied dependency expressed through field 'circuitBreaker'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getCircuitBreaker' defined in class path resource [com/example/circuitbreaker/config/CircuitBreakerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.github.resilience4j.circuitbreaker.CircuitBreaker]: Factory method 'getCircuitBreaker' threw exception; nested exception is java.lang.IllegalArgumentException: Non-serializable object at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.5.jar:2.7.5] at com.example.circuitbreaker.CircuitBreakerApplication.main(CircuitBreakerApplication.java:10) ~[classes/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getCircuitBreaker' defined in class path resource [com/example/circuitbreaker/config/CircuitBreakerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.github.resilience4j.circuitbreaker.CircuitBreaker]: Factory method 'getCircuitBreaker' threw exception; nested exception is java.lang.IllegalArgumentException: Non-serializable object at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.23.jar:5.3.23] ... 20 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.github.resilience4j.circuitbreaker.CircuitBreaker]: Factory method 'getCircuitBreaker' threw exception; nested exception is java.lang.IllegalArgumentException: Non-serializable object at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.23.jar:5.3.23] ... 33 common frames omitted Caused by: java.lang.IllegalArgumentException: Non-serializable object at net.spy.memcached.transcoders.BaseSerializingTranscoder.serialize(BaseSerializingTranscoder.java:110) ~[spymemcached-2.12.3.jar:2.12.3] at net.spy.memcached.transcoders.SerializingTranscoder.encode(SerializingTranscoder.java:162) ~[spymemcached-2.12.3.jar:2.12.3] at net.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:304) ~[spymemcached-2.12.3.jar:2.12.3] at net.spy.memcached.MemcachedClient.replace(MemcachedClient.java:967) ~[spymemcached-2.12.3.jar:2.12.3] at com.example.circuitbreaker.experimentalCache.MemcachedCache.replace(MemcachedCache.java:560) ~[classes/:na] at com.example.circuitbreaker.experimentalCache.MemcachedCache.invoke(MemcachedCache.java:647) ~[classes/:na] at io.github.resilience4j.cache.CacheRegistryStore.computeIfAbsent(CacheRegistryStore.java:25) ~[resilience4j-cache-1.7.1.jar:1.7.1] at io.github.resilience4j.core.registry.AbstractRegistry.computeIfAbsent(AbstractRegistry.java:102) ~[resilience4j-core-1.7.0.jar:1.7.0] at io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry.circuitBreaker(InMemoryCircuitBreakerRegistry.java:166) ~[resilience4j-circuitbreaker-1.7.0.jar:1.7.0] at io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry.circuitBreaker(InMemoryCircuitBreakerRegistry.java:160) ~[resilience4j-circuitbreaker-1.7.0.jar:1.7.0] at io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry.circuitBreaker(InMemoryCircuitBreakerRegistry.java:147) ~[resilience4j-circuitbreaker-1.7.0.jar:1.7.0] at com.example.circuitbreaker.config.CircuitBreakerConfiguration.getCircuitBreaker(CircuitBreakerConfiguration.java:78) ~[classes/:na] at com.example.circuitbreaker.config.CircuitBreakerConfiguration$$EnhancerBySpringCGLIB$$20596377.CGLIB$getCircuitBreaker$2(<generated>) ~[classes/:na] at com.example.circuitbreaker.config.CircuitBreakerConfiguration$$EnhancerBySpringCGLIB$$20596377$$FastClassBySpringCGLIB$$9d3cadb7.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.23.jar:5.3.23] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.23.jar:5.3.23] at com.example.circuitbreaker.config.CircuitBreakerConfiguration$$EnhancerBySpringCGLIB$$20596377.getCircuitBreaker(<generated>) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.23.jar:5.3.23] ... 34 common frames omitted Caused by: java.io.NotSerializableException: io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1197) ~[na:na] at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354) ~[na:na] at net.spy.memcached.transcoders.BaseSerializingTranscoder.serialize(BaseSerializingTranscoder.java:105) ~[spymemcached-2.12.3.jar:2.12.3] ... 55 common frames omitted
Notice that: Caused by: java.io.NotSerializableException: io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (2 by maintainers)
Hello @marcosabelenda ,
what a coincidence, I’m trying to do exactly the same thing and I have the same exact problem. The docs is not clear at all in this particular part.
Hopefully someone provide us a solution
Ok, i’ll check it out. Thank you so much!