When using a @JmsListener
it uses a DefaultMessageListenerContainer
which extends JmsDestinationAccessor
which by default has the pubSubDomain
set to false
. When this property is false it is operating on a queue. If you want to use topics you have to set this properties value to true
.
As you are using Spring Boot you can quite easily set this property to true by adding the spring.jms.pub-sub-domain
property to the application.properties
and set it to true
.
spring.jms.pub-sub-domain=true
When using a @JmsListener
it is looking for a jmsListenerContainerFactory
named bean, if that isn't available a default one is expected. You can also include your own bean and programmatically set this property yo true
.
@Bean
public DefaultMessageListenerContainer jmsListenerContainerFactory() {
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
dmlc.setPubSubDomain(true);
// Other configuration here
return dmlc;
}
This would of course also work but would be more work, more information on this can be found in the documentation of the @EnableJms
annotation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…