Skip to content

Make jmsListenerContainerFactory @ConditionalOnSingleCandidate #12700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danlangford opened this issue Mar 30, 2018 · 1 comment
Closed

Make jmsListenerContainerFactory @ConditionalOnSingleCandidate #12700

danlangford opened this issue Mar 30, 2018 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@danlangford
Copy link

danlangford commented Mar 30, 2018

I am wondering if it would be appropriate to add @ConditionalOnSingleCandidate to jmsListenerContainerFactory? I have an application that sends messages to multiple brokers and as such i create multiple ConnectionFactory and JMSTemplate beans. My application does not need to listen to any JMS destinations. my application fails to start because it is finding multiple ConnectionFactory beans and as such unable to create the default jmsListenerContainerFactory bean. For clarity, my application does not need a listener.

if i understand this correctly we are getting into this position because due to the MATCHED conditions listed below.

AutoConfigure on class JmsAutoConfiguration:

@Configuration
@ConditionalOnClass({ Message.class, JmsTemplate.class })
@ConditionalOnBean(ConnectionFactory.class)
@EnableConfigurationProperties(JmsProperties.class)
@Import(JmsAnnotationDrivenConfiguration.class)
public class JmsAutoConfiguration {

@ConditionalOnClass({ Message.class, JmsTemplate.class }) MATCHES those ARE on the classpath
@ConditionalOnBean(ConnectionFactory.class) MATCHES i have multiple CopnnectionFactories
@Import(JmsAnnotationDrivenConfiguration.class)

Configure JmsAnnotationDrivenConfiguration:

@Configuration
@ConditionalOnClass(EnableJms.class)
class JmsAnnotationDrivenConfiguration {

@ConditionalOnClass(EnableJms.class) MATCHES that class is on the classpath

@Bean
@ConditionalOnMissingBean(name = "jmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
DefaultJmsListenerContainerFactoryConfigurer configurer,
ConnectionFactory connectionFactory) {

@ConditionalOnMissingBean(name = "jmsListenerContainerFactory") MATCHES i did not define my own

and then that method is requiring just one ConnectionFactory parameter but I have made multiple.

would adding @ConditionalOnSingleCandidate be a quality of life improvement here? Would it make it so that a listenerContainerFactory is not created and my application can start without error? or am i misunderstanding the use/purpose of that annotation?

workarounds i played with trying to get my application to start

  • i set spring.jms.listener.auto-startup=false however the problem persisted
  • i can make a ConnectionFactory Bean @Primary but.... i dont want or need a listener so it feels like that is making the error go away by conforming to its current design. its allowing its current design to dictate how my application is configured which is incorrect and misleading to other developers. none of my connections are necessarily Primary
  • currently i have created my own jmsListenerContainerFactory bean so that spring-boot does not try to autoconfigure its own. this is messier than the @Primary work around from a code quality point of view but at least i know i am killing the creation of a listenerContainerFactory as early as i can see to kill it.

or have I missed something and I am way off base? is there some other property to communicate to spring "please do not register any listeners"?

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 30, 2018
@snicoll
Copy link
Member

snicoll commented Apr 3, 2018

@danlangford you're right and the auto-configuration was not designed to account for the multi-datasource scenario. One solution that you didn't mention is to exclude JmsAutoConfiguration for the time being.

We've done that work in 2.0 for JPA and DataSource but I am afraid we should have revisited this part as well. Let's try to tackle that for the next feature release.

@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 3, 2018
@snicoll snicoll added this to the Backlog milestone Apr 3, 2018
@wilkinsona wilkinsona changed the title appropriate to add @ConditionalOnSingleCandidate to jmsListenerContainerFactory? Make jmsListenerContainerFactory @ConditionalOnSingleCandidate Jun 1, 2018
@mbhave mbhave self-assigned this Sep 4, 2018
@mbhave mbhave modified the milestones: Backlog, 2.1.0.M3 Sep 4, 2018
@mbhave mbhave closed this as completed in 75937f5 Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants