I am setting up a durable JMS topic consumer using SpringBoot and activeMQ. I was able to get everything working (successfully running as durable consumer) using the spring boot @JmsListener annotation. But, because I would like to dynamically create listeners, I am trying to create them using the JmsListenerConfiguraion interface instead.
Using the code below the topic consumer is successfully created and consumes messages. But, the problem is that the consumer it creates is not durable. I am setting clientId, setSubscriptionDurable to true, and setting setPubSubDomain to true on the factory. What am I missing?
@Configuration
@EnableJms
public class ListenerConfigurer implements JmsListenerConfigurer {
@Autowired
private List<JmsListenerConfig> listenerConfigs;
@Autowired
private ConnectionFactory connectionFactory;
@Override
public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {
for(JmsListenerConfig jmsListenerConfig : listenerConfigs) {
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
endpoint.setId(jmsListenerConfig.getEndpointName());
endpoint.setDestination(jmsListenerConfig.getEndpointName());
endpoint.setMessageListener(message -> {
TextMessage txtMessage = (TextMessage) message;
try {
jmsListenerConfig.getMessageReceiveHandler().handle(txtMessage.getText());
}catch (JMSException e){
e.printStackTrace();
}
});
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setSubscriptionDurable(true);
factory.setPubSubDomain(true);
factory.setClientId(jmsListenerConfig.getClientUid());
DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
endpoint.setupListenerContainer(container);
registrar.registerEndpoint(endpoint, factory);
registrar.setContainerFactory(factory);
}
}
}
List<JmsListenerConfig> listenerConfigs
because I have a similar requirement but I don't understand how to get a list. – damndemon