I am trying to create example for publish-subscribe based on @JmsListener annotation: https://github.com/lkrnac/book-eiws-code-samples/tree/master/05-jms/0515-publish-subscr
Switching the default destination type of a @JmsListener
from Queue
to Topic
can be done completely in Java without modifying the properties or using XML.
The Spring guide contains an example for customizing the default settings provided by DefaultMessageListenerContainer
.
It requires defining a custom bean like follows:
@Bean
public JmsListenerContainerFactory> myFactory(ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
// This provides all boot's default to this factory, including the message converter
configurer.configure(factory, connectionFactory);
// You could still override some of Boot's default if necessary.
factory.setPubSubDomain(true);
return factory;
}
This can then be used in the @JmsListener
annotated method:
@JmsListener(destination = "mailbox", containerFactory = "myFactory")
public void receiveMessage(Email email) {
// implementation
}