I'm trying to use DefaultMessageListenerContainer with ActiveMQ in a specific configuration : the ActiveMQ configuration is loaded dynamically after the broker has started. However one of the application is already started before the configuration is loaded and that application tries to connect to a queue to which it initially doesn't have access (user not existing).
The connection is done using a DefaultMessageListenerContainer. The error we're seeing is following:
DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'js04.admin.adminweb' - retrying using FixedBackOff{inter val=5000, currentAttempts=7, maxAttempts=unlimited}. Cause: The JMS connection has failed: Socket closed
Once the final configuration is loaded into the broker, the error keeps on occuring even though all the rights are in place (we're able to connect using a DefaultMessageListenerContainer with the same parameters created after the configuration is in place).
I've done some researches and found that the exception sometimes didn't trigger a socket reconnection, so I've updated my DefaultMessageListenerContainer with an ExceptionListener, but that didn't improve it.
Here's the declaration of my beans:
@Bean
public ConnectionFactory jmsFactory() {
final org.apache.activemq.ActiveMQConnectionFactory activeMQConnectionFactory = new org.apache.activemq.ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(brokerURL);
activeMQConnectionFactory.setUserName(jmsUserUsername);
activeMQConnectionFactory.setPassword(jmsUserPassword);
return activeMQConnectionFactory;
}
@Bean
public org.springframework.jms.connection.CachingConnectionFactory jmsConsumerConnectionFactory() {
final org.springframework.jms.connection.CachingConnectionFactory singleConnectionFactory = new org.springframework.jms.connection.CachingConnectionFactory(
jmsFactory());
return singleConnectionFactory;
}
@Bean
public org.apache.activemq.command.ActiveMQQueue queueName() {
return new org.apache.activemq.command.ActiveMQQueue(QueueHelper.adminQueue(journalingID, backend.getComponentType().Value));
}
@Bean
public org.springframework.jms.core.JmsTemplate jmsTemplate() {
final JmsTemplate template = new org.springframework.jms.core.JmsTemplate();
template.setConnectionFactory(jmsConsumerConnectionFactory());
template.setDefaultDestination(queueName());
template.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
return template;
}
@Bean
public AdminQueueMessageListener adminQueueMessageListener() {
return new AdminQueueMessageListener(backend, journalingID, jmsTemplate());
}
@Bean
public QueueHelper queueHelper() {
return new QueueHelper();
}
@Bean
public DefaultMessageListenerContainer msgListenerContainer() {
final DefaultMessageListenerContainer msgListenerContainer = new DefaultMessageListenerContainer();
msgListenerContainer.setExceptionListener(jmsConsumerConnectionFactory());
msgListenerContainer.setConcurrentConsumers(1);
msgListenerContainer.setMaxConcurrentConsumers(1);
msgListenerContainer.setReceiveTimeout(5000);
msgListenerContainer.setIdleConsumerLimit(1);
msgListenerContainer.setIdleConsumerLimit(5);
msgListenerContainer.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
msgListenerContainer.setSessionTransacted(true);
msgListenerContainer.setConnectionFactory(jmsConsumerConnectionFactory());
msgListenerContainer.setDestinationName("");
msgListenerContainer.setMessageListener(adminQueueMessageListener());
return msgListenerContainer;
}
Any idea as to why the connection is not successful once the broker is loaded with the correct configuration ?
Aucun commentaire:
Enregistrer un commentaire