I use spring boot with java 17 and activemq.
When an exception occurs I want to retry with delay 60 seconds.
The problem is that every time an exception is thrown in my application, the number of retries is 7 and there is no delay between them.
Could you please check my code?
@Configuration
@Slf4j
public class JmsConfig {
@Value("${jms.activemq.brokerUrl}")
private String brokerUrl;
@Value("${jms.activemq.user}")
private String brokerUsername;
@Value("${jms.activemq.password}")
private String brokerPassword;
@Bean
public ConnectionFactory connectionFactory() {
ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory();
factory.setBrokerURL(brokerUrl);
factory.setUserName(brokerUsername);
factory.setPassword(brokerPassword);
factory.setTrustAllPackages(true);
return factory;
}
@Bean
public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
return jmsTemplate;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setTransactionManager(new JmsTransactionManager(connectionFactory));
factory.setConcurrency("1-1");
return factory;
}
}
The code bellow is in my service
@JmsListener(destination = "test")
@Transactional
@Retryable(maxAttempts = 4, backoff = @Backoff(delay = 60000))
public void receiveMessage(ObjectMessage message) throws JMSException {
LOG.info("receiveMessage started......");
try {
.......
} catch (JMSException | ClassCastException e) {
LOG.error("Error while processing the message", e);
throw e;
}
}