I am using JMS listener with spring boot and want to control message dequeing from queue only when the message been processed successfully. I have set session acknowledgement mode to client acknowledgement and i see in case of exception , message.acknowledge method is not getting executed, still the message is being removed from queue. Any idea where i am going wrong. thanks in advance -
jms configuration -
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setSessionTransacted(true);
factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
factory.setConcurrency(jmsConcurrentConnection);
factory.setRecoveryInterval(Long.parseLong(jmsConnectionRecoveryInterval));
factory.setErrorHandler(jmsErrorHandler);
configurer.configure(factory, connectionFactory);
return factory;
}
Message processing code-
@JmsListener(destination = "${queue_name}")
public void listenMessage(Message message) throws JMSException {
if (message instanceof TextMessage) {
TextMessage messageFromQueue = (TextMessage) message;
try {
processService.processData(
messageFromQueue.getText(), processHeaders(messageFromQueue));
log.debug("Received message processed successfully!");
message.acknowledge();
} catch (JMSException e) {
log.error("Exception occurred :" + e.getMessage());
} catch (ResourceAccessException e) {
log.error("IOException occurred : [{}]", e.getMessage());
} catch (CustomRuntimeException e) {
log.error(
"CustomRuntimeException occurred. message couldn't be processed successfully");
}
When i get any unforseen runtime error, i see the log in the CustomRuntimeException method being executed and that time log.debug("Received message processed successfully!") is not getting printed. That means my message.acknowledge method is not getting processed but i see the message being removed from queue, which i do not want. I want to hold the message in the queue in case it has not been processed successfully.