spring-cloud-stream
spring-cloud-stream copied to clipboard
Unable to use StreamBridge to send a message inside a consumer
Describe the issue
I am trying to send a message from a spring cloud stream consumer method using the StreamBridge
utility. I am able to use StreamBridge
from any normal method and just not a spring cloud stream Consumer method due to a RuntimeException about circular references. Please see log output below.
I tried a Function<> ( instead of a Consumer<> ) and registered both in
and out
bindings for it. This eliminated the need for the StreamBridge
reference. But, this forces me to produce a corresponding message for every incoming message. One of our needs is to only optionally produce messages based on the processing of the incoming message. I can also think of scenarios where I might have to produce to different bindings based on incoming message that cannot be supported.
mcpEstimateServiceApi | 2024-10-17T14:31:03.901Z INFO 7 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 30000 (http)
mcpEstimateServiceApi | 2024-10-17T14:31:03.925Z INFO 7 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
mcpEstimateServiceApi | 2024-10-17T14:31:03.926Z INFO 7 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.25]
mcpEstimateServiceApi | 2024-10-17T14:31:04.150Z INFO 7 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
mcpEstimateServiceApi | 2024-10-17T14:31:04.150Z INFO 7 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3766 ms
mcpEstimateServiceApi | 2024-10-17T14:31:04.389Z WARN 7 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancellin
g refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app': Unsatisfied dependency expressed through field 'streamBridge': Erro
r creating bean with name 'streamBridgeUtils' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Unsatisfied dependency expressed throug
h method 'streamBridgeUtils' parameter 0: Error creating bean with name 'functionCatalog' defined in class path resource [org/springframework/cloud/function/context/config/ContextFunctionCa
talogAutoConfiguration.class]: Unsatisfied dependency expressed through method 'functionCatalog' parameter 0: Error creating bean with name 'app': Requested bean is currently in creation: Is there an unresolvable circular reference?
mcpEstimateServiceApi | 2024-10-17T14:31:04.397Z INFO 7 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
mcpEstimateServiceApi | 2024-10-17T14:31:04.418Z INFO 7 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
mcpEstimateServiceApi |
mcpEstimateServiceApi | Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
mcpEstimateServiceApi | 2024-10-17T14:31:04.485Z ERROR 7 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
mcpEstimateServiceApi |
mcpEstimateServiceApi | ***************************
mcpEstimateServiceApi | APPLICATION FAILED TO START
mcpEstimateServiceApi | ***************************
mcpEstimateServiceApi |
mcpEstimateServiceApi | Description:
mcpEstimateServiceApi |
mcpEstimateServiceApi | The dependencies of some of the beans in the application context form a cycle:
mcpEstimateServiceApi |
mcpEstimateServiceApi | ┌─────┐
mcpEstimateServiceApi | | app (field private org.springframework.cloud.stream.function.StreamBridge mcp.estimates.App.streamBridge)
mcpEstimateServiceApi | ↑ ↓
mcpEstimateServiceApi | | streamBridgeUtils defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]
mcpEstimateServiceApi | ↑ ↓
mcpEstimateServiceApi | | functionCatalog defined in class path resource [org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.class]
mcpEstimateServiceApi | └─────┘
mcpEstimateServiceApi |
mcpEstimateServiceApi |
mcpEstimateServiceApi | Action:
mcpEstimateServiceApi |
mcpEstimateServiceApi | Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
mcpEstimateServiceApi |
mcpEstimateServiceApi | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app': Unsatisfied dependency expressed through field 'streamBrid
ge': Error creating bean with name 'streamBridgeUtils' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Unsatisfied dependency express
ed through method 'streamBridgeUtils' parameter 0: Error creating bean with name 'functionCatalog' defined in class path resource [org/springframework/cloud/function/context/config/ContextF
unctionCatalogAutoConfiguration.class]: Unsatisfied dependency expressed through method 'functionCatalog' parameter 0: Error creating bean with name 'app': Requested bean is currently in creation: Is there an unresolvable circular reference?
mcpEstimateServiceApi | at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:767)
mcpEstimateServiceApi | at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:747)
mcpEstimateServiceApi | at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145)
mcpEstimateServiceApi | at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:492)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1416)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973)
mcpEstimateServiceApi | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:950)
mcpEstimateServiceApi | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616)
mcpEstimateServiceApi | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
mcpEstimateServiceApi | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:738)
mcpEstimateServiceApi | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:440)
mcpEstimateServiceApi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
mcpEstimateServiceApi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
mcpEstimateServiceApi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
mcpEstimateServiceApi | at mcp.estimates.App.main(App.java:43)
mcpEstimateServiceApi | at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
mcpEstimateServiceApi | at java.base/java.lang.reflect.Method.invoke(Method.java:580)
mcpEstimateServiceApi | at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:102)
mcpEstimateServiceApi | at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:64)
mcpEstimateServiceApi | at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)
mcpEstimateServiceApi | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'streamBridgeUtils' defined in class path resource [or
g/springframework/cloud/stream/function/FunctionConfiguration.class]: Unsatisfied dependency expressed through method 'streamBridgeUtils' parameter 0: Error creating bean with name 'functio
nCatalog' defined in class path resource [org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.class]: Unsatisfied dependency expressed through method 'functionCatalog' parameter 0: Error creating bean with name 'app': Requested bean is currently in creation: Is there an unresolvable circular reference?
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:801)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:545)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mcpEstimateServiceApi | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1417)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337)
mcpEstimateServiceApi | at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:764)
mcpEstimateServiceApi | ... 25 more
mcpEstimateServiceApi | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'functionCatalog' defined in class path resource [org/
springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.class]: Unsatisfied dependency expressed through method 'functionCatalog' parameter 0: Error creating bean with name 'app': Requested bean is currently in creation: Is there an unresolvable circular reference?
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:801)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:545)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mcpEstimateServiceApi | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1417)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:910)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
mcpEstimateServiceApi | ... 38 more
mcpEstimateServiceApi | Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'app': Requested bean is currently in creation: Is there an unresolvable circular reference?
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:412)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
mcpEstimateServiceApi | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1633)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1597)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1488)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1375)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:910)
mcpEstimateServiceApi | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
mcpEstimateServiceApi | ... 52 more
mcpEstimateServiceApi exited with code 1
Sensitivity: Company-Internal
====================
This email/fax message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information.
Any unauthorized review, use, disclosure or distribution of this
email/fax is prohibited. If you are not the intended recipient, please
destroy all paper and electronic copies of the original message.