How to add multiple JMS MessageListners to one MessageListenerContainer for Spring Java configuration

I had the following xml code in my spring -config.xml

<jms:listener-container acknowledge="auto" connection-factory="cachedConnectionFactory" container-type="default" error-handler="consumerErrorHandler" concurrency="20-25"> <jms:listener destination="#{TaskFinished.destination}" method="onMessage" ref="taskFinished" /> </jms:listener-container> 

Now I have converted the spring xml configuration file to the Java configuration.

I translated it as

 @Bean(name = "consumerJmsListenerContainer") public DefaultMessageListenerContainer consumerJmsListenerContainer() { DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer(); messageListenerContainer .setConnectionFactory(cachingConnectionFactory()); messageListenerContainer.setConcurrency("20-25"); messageListenerContainer.setErrorHandler(new ConsumerErrorHandler()); messageListenerContainer .setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE); messageListenerContainer.setMessageListener(new TaskFinished()); return messageListenerContainer; } 

What do I need to know if there was more than one MessageListner in the message container, for example

 <jms:listener-container acknowledge="auto" connection-factory="cachedConnectionFactory" container-type="default" error-handler="consumerErrorHandler" concurrency="20-25"> <jms:listener destination="#{questionGeneration.destination}" method="onMessage" ref="questionGeneration" /> <jms:listener destination="#{friendShipLogic.destination}" method="onMessage" ref="friendShipLogic" /> <jms:listener destination="#{postAvailabilityChecker.destination}" method="onMessage" ref="postAvailabilityChecker" /> <jms:listener destination="#{playOn.destination}" method="onMessage" ref="playOn" /> </jms:listener-container> 

How could I convert this xml code to java configuration?

+7
java spring xml spring-jms jms
source share
2 answers

The namespace is just a convenience - each <jms:listener/> element gets its own DMLC ; the outer (container) element is simply a vehicle for providing common attributes.

+8
source share

You can add container.setConcurrentConsumers(10); where the number of users is 10

0
source share

All Articles