micronaut-projects / micronaut-jms

Integration between Micronaut and JMS
Apache License 2.0
15 stars 14 forks source link

Proper way to disable listeners? #67

Closed drmaciej closed 3 years ago

drmaciej commented 3 years ago

I'm aware of micronaut.jms.sqs.enabled. I was expecting to set this to false and completely disable any JMS/SQS-related functionality. Instead, the framework attempts to create listeners.

Is the proper solution adding @Requires(property = SqsConfigurationProperties.PREFIX + ".enabled", value = "true") to listeners? Or should micronaut.jms.sqs.enabled cover that?

Task List

Steps to Reproduce

  1. Add a listener annotated with @JMSListener(CONNECTION_FACTORY_BEAN_NAME)
  2. Set micronaut.jms.sqs.enabled to false.
  3. Run your application

Expected Behaviour

Application starts without any issue.

Actual Behaviour

Application fails to start:

io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.jms.pool.JMSConnectionPool] exists for the given qualifier: @Named('sqsJmsConnectionFactory'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2348)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:721)
    at io.micronaut.jms.configuration.AbstractJMSListenerMethodProcessor.registerListener(AbstractJMSListenerMethodProcessor.java:155)
    at io.micronaut.jms.configuration.AbstractJMSListenerMethodProcessor.process(AbstractJMSListenerMethodProcessor.java:90)
    at io.micronaut.context.DefaultBeanContext.lambda$null$31(DefaultBeanContext.java:1621)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
    at io.micronaut.context.DefaultBeanContext.lambda$initializeContext$32(DefaultBeanContext.java:1597)
    at java.base/java.util.HashMap.forEach(HashMap.java:1336)
    at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1595)
    at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220)
    at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2838)
    at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:233)
    at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166)
    at io.micronaut.runtime.Micronaut.start(Micronaut.java:71)
    at io.micronaut.runtime.Micronaut.run(Micronaut.java:311)
    at io.micronaut.runtime.Micronaut.run(Micronaut.java:297)
    at ***.Application.main(Application.java:10)

Environment Information

Example Application

elliottpope commented 3 years ago

I think this behaviour is mostly as expected from the library's point of view. The library does not take a particular opinion on which listeners correspond to which broker (you could be using SQS, ActiveMQ, both, or a custom broker in your project). It will attempt to configure the listener expecting that you may swap out brokers using external configuration.

I would suggest that you annotation your listener with @Requires(property = SqsConfigurationProperties.PREFIX + ".enabled", value = "true") as you suggested.

drmaciej commented 3 years ago

thanks @elliottpope; I'll keep using that.