1

I put @ServiceActivator to log all messages that gave error to kafka:

@ServiceActivator(inputChannel = "errorChannel")
public void handleErrors(final ErrorMessage in) {
    log.error("encountered exception" + em.toString());
}

and I'm also setting the errorChannelEnabled flag to true:

  cloud:
    stream:
      function:
        definition: consumeProfile
      bindings:
        #kafka producer
        produceProfile-out-0:
          binder: kafka
          destination: profile
          producer:
            use-native-encoding: true
            error-channel-enabled: true

the problem is when I'm uploading the application I'm getting this error log:

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'profileListener.handleErrors.serviceActivator': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1160) ~[spring-context-5.3.21.jar:5.3.21]
    at org.springframework.integration.monitor.IntegrationMBeanExporter.enhanceHandlerMonitor(IntegrationMBeanExporter.java:865) ~[spring-integration-jmx-5.5.13.jar:5.5.13]
    at org.springframework.integration.monitor.IntegrationMBeanExporter.registerHandler(IntegrationMBeanExporter.java:695) ~[spring-integration-jmx-5.5.13.jar:5.5.13]
    at org.springframework.integration.monitor.IntegrationMBeanExporter.postProcessAbstractEndpoint(IntegrationMBeanExporter.java:340) ~[spring-integration-jmx-5.5.13.jar:5.5.13]
    at org.springframework.integration.monitor.IntegrationMBeanExporter.postProcessAfterInitialization(IntegrationMBeanExporter.java:324) ~[spring-integration-jmx-5.5.13.jar:5.5.13]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessMethodAndRegisterEndpointIfAny(MessagingAnnotationPostProcessor.java:257) ~[spring-integration-core-5.5.13.jar:5.5.13]
    at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.lambda$processAnnotationTypeOnMethod$1(MessagingAnnotationPostProcessor.java:215) ~[spring-integration-core-5.5.13.jar:5.5.13]
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
    at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.afterSingletonsInstantiated(MessagingAnnotationPostProcessor.java:136) ~[spring-integration-core-5.5.13.jar:5.5.13]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:974) ~[spring-beans-5.3.21.jar:5.3.21]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.21.jar:5.3.21]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.21.jar:5.3.21]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.1.jar:2.7.1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.1.jar:2.7.1]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.1.jar:2.7.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.1.jar:2.7.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.1.jar:2.7.1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.1.jar:2.7.1]
    at com.github.victorsilva95.pocspringcloudstreamkafka.PocSpringCloudStreamKafkaApplication.main(PocSpringCloudStreamKafkaApplication.java:14) ~[main/:na]

my application does not crash because of this exception, but I wanted your help to understand the reason, thank you

victor hugo
  • 85
  • 1
  • 1
  • 8
  • Any chances to have a simple project from you to let us to reproduce and play with? – Artem Bilan Jul 04 '22 at 15:28
  • Hi Artem, thanks for the help, I just committed my project on github: https://github.com/victorsilva95/poc-spring-cloud-stream-kafka i'm using mysql and kafka in docker-compose. What I want is to have a callback when I send an event to the kafka topic similar to kafkaTemplate.send that returns a callback, but using the spring cloud stream. – victor hugo Jul 04 '22 at 15:53

1 Answers1

1

Thank you for the sample.

This is a bug in the IntegrationMBeanExporter: we try to pull an endpoint bean at the moment it is created by the MessagingAnnotationPostProcessor.

So, please, raise a GH issue in the Spring Integration project and we will see what we can do.

Meanwhile as a workaround you can turn off JMX by respective Srping Boot property: spring.jmx.enabled=false. We have it auto-configured by default for Spring Integration regardless of Spring Boot default decision:

@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
protected static class IntegrationJmxConfiguration {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • hi artem and thanks for the help again, I would like to ask one more question if possible, is there a way to use some kind of return callback similar to KafkaTemplate.send in StreamBridge to log in if the message is sent successfully or if for some reason there was an error? example in kafka template: ListenableFuture> future = kafkaTemplate.send(topicName, message); future.addCallback(new ListenableFutureCallback>() is there a similar way in spring cloud stream? – victor hugo Jul 05 '22 at 16:09
  • hi Artem another point, I set the mentioned property: spring.jmx.enabled=false in my application.yaml, but the error still persists, I will open a bug as you suggested in spring integration. – victor hugo Jul 05 '22 at 16:22
  • I noticed that, too when I run your app from IDEA. The run for Spring Boot has enabled JMX Agent by default. Try to run your app from the outside of the IDE. The question about callback deserves its own SO thread. – Artem Bilan Jul 05 '22 at 16:26
  • thanks artemis, you were correct my ide was passing this parameter in the run configurations as true, last question please, the bridge.send method, is asynchronous right? its return is a boolean informing if it sent successfully or not, would it be possible to log a message if there is an error in sending? – victor hugo Jul 05 '22 at 16:40
  • That’s the part where you provide a `ProducerListener` for Kafka binder. Please, new SO thread with more details – Artem Bilan Jul 05 '22 at 16:42
  • Strange: I cannot reproduce it in Spring Integration `5.5.x` by itself, but it definitely fail against the latest version with your application. Investigating... – Artem Bilan Jul 07 '22 at 16:41
  • Here is the fix: https://github.com/spring-projects/spring-integration/pull/3837. Worked well with your sample. Thank you! – Artem Bilan Jul 07 '22 at 19:32