I have a transaction manager set up for consumer.
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
@Qualifier("jmsSimpleConnectionFactory") ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer containerFactoryConfigurer,
PlatformTransactionManager transactionManager) {
DefaultJmsListenerContainerFactory listenerContainerFactory = new DefaultJmsListenerContainerFactory();
containerFactoryConfigurer.configure(listenerContainerFactory, connectionFactory);
listenerContainerFactory.setMessageConverter(this.jmsMessageConverter);
listenerContainerFactory.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
listenerContainerFactory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONNECTION);
listenerContainerFactory.setTransactionManager(transactionManager);
...
@Bean
public PlatformTransactionManager transactionManager(ConnectionFactory connectionFactory) {
return new JmsTransactionManager(connectionFactory);
}
Also, the ability is configured from the service to automatically pick up messages from the DLL and send them back to the queue so that the service can re-process them.
@Bean
public DefaultJmsListenerContainerFactory dlqListenerContainerFactory(PlatformTransactionManager transactionManager) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(jmsSimpleConnectionFactory);
factory.setTransactionManager(transactionManager);
factory.setSessionTransacted(true);
return factory;
}
@JmsListener(destination = "DLQ", containerFactory = "dlqListenerContainerFactory")
public void processDLQMessage(String message) {
jmsTemplate.convertAndSend(sourceQueue, message);
}
However, this approach works. When an exception appears in the consumer's transactional method (the method is marked with the @Transactional annotation) and the transaction is considered unsuccessful, only then the message being processed will be placed in the DLQ.
But if at the time of processing the message the consumer service turns off then such a message will simply disappear from the queue. However, I would like it to be delivered processed to the queue.
What else can be configured? Share your knowledge.