BackOff and transactional not working for mesage handling only for listener setup

I have a IbmMqEndpoint that receives messages. What I want is to put the message back in the original queue if an error occurs during message processing. The follwoing implementation works flawlessly processes error-free messages.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> @Bean(name = "ibmMqListenerContainerFactory")
public DefaultJmsListenerContainerFactory ibmMqListenerContainerFactory(
@Qualifier("ibmMqConnectionFactory") ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setSessionTransacted(true);
factory.setBackOff(new FixedBackOff(5000L, 3));
factory.setErrorHandler(new ErrorHandler() {
@Override
public void handleError(Throwable t) {
logger.warn("spring jms custom error handling example");
logger.error(t.getCause().getMessage());
throw new MessageSendException("Error", new Exception("Test"));
}
});
return factory;
}
</code>
<code> @Bean(name = "ibmMqListenerContainerFactory") public DefaultJmsListenerContainerFactory ibmMqListenerContainerFactory( @Qualifier("ibmMqConnectionFactory") ConnectionFactory connectionFactory) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(connectionFactory); factory.setSessionTransacted(true); factory.setBackOff(new FixedBackOff(5000L, 3)); factory.setErrorHandler(new ErrorHandler() { @Override public void handleError(Throwable t) { logger.warn("spring jms custom error handling example"); logger.error(t.getCause().getMessage()); throw new MessageSendException("Error", new Exception("Test")); } }); return factory; } </code>
   @Bean(name = "ibmMqListenerContainerFactory")
   public DefaultJmsListenerContainerFactory ibmMqListenerContainerFactory(
                                             @Qualifier("ibmMqConnectionFactory") ConnectionFactory connectionFactory) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setSessionTransacted(true);
    factory.setBackOff(new FixedBackOff(5000L, 3));
    factory.setErrorHandler(new ErrorHandler() {
        @Override
        public void handleError(Throwable t) {
            logger.warn("spring jms custom error handling example");
            logger.error(t.getCause().getMessage());
            throw new MessageSendException("Error", new Exception("Test"));
        }
    });
    return factory;
}

The follwing registers the MessageListener:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>private SimpleJmsListenerEndpoint getJmsListenerEndpoint(String endpoint) {
SimpleJmsListenerEndpoint jmsListenerEndpoint = new SimpleJmsListenerEndpoint();
jmsListenerEndpoint.setId(endpoint);
jmsListenerEndpoint.setDestination(endpoint);
jmsListenerEndpoint.setMessageListener(m -> {
try {
byte[] body = m.getBody(byte[].class);
MyMessage myMessage = new MyMessage(body);
messageHandler.accept(myMessage);
} catch MessageSendException | JMSException e) {
throw new MessageSendException(e);
}
});
return jmsListenerEndpoint;
}
</code>
<code>private SimpleJmsListenerEndpoint getJmsListenerEndpoint(String endpoint) { SimpleJmsListenerEndpoint jmsListenerEndpoint = new SimpleJmsListenerEndpoint(); jmsListenerEndpoint.setId(endpoint); jmsListenerEndpoint.setDestination(endpoint); jmsListenerEndpoint.setMessageListener(m -> { try { byte[] body = m.getBody(byte[].class); MyMessage myMessage = new MyMessage(body); messageHandler.accept(myMessage); } catch MessageSendException | JMSException e) { throw new MessageSendException(e); } }); return jmsListenerEndpoint; } </code>
private SimpleJmsListenerEndpoint getJmsListenerEndpoint(String endpoint) {
    SimpleJmsListenerEndpoint jmsListenerEndpoint = new SimpleJmsListenerEndpoint();
    jmsListenerEndpoint.setId(endpoint);
    jmsListenerEndpoint.setDestination(endpoint);

    jmsListenerEndpoint.setMessageListener(m -> {
        try {

            byte[] body = m.getBody(byte[].class);
            MyMessage myMessage = new MyMessage(body);
            messageHandler.accept(myMessage);
  
        } catch MessageSendException | JMSException e) {
            throw new MessageSendException(e);
        }
    });
    return jmsListenerEndpoint;
}

However, after the messageListener is set and I send an faulty message and this the MessageSentException gets thrown, the underlying DefaultMessageListenerContainer implementation resets the BackOff-variable currentAttempts by calling backOff.start() in the method

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> private void waitBeforeRecoveryAttempt() {
BackOffExecution execution = DefaultMessageListenerContainer.this.backOff.start();
DefaultMessageListenerContainer.this.applyBackOffTime(execution);
}
</code>
<code> private void waitBeforeRecoveryAttempt() { BackOffExecution execution = DefaultMessageListenerContainer.this.backOff.start(); DefaultMessageListenerContainer.this.applyBackOffTime(execution); } </code>
 private void waitBeforeRecoveryAttempt() {
        BackOffExecution execution = DefaultMessageListenerContainer.this.backOff.start();
        DefaultMessageListenerContainer.this.applyBackOffTime(execution);
    }

What caught my attention is, that the method handleListenerSetupFailure in DefaultMessageListenerContainer is called. But this isn’t a handler setup failure, is it? I thought this is a message-handling failure, as the setup took place on application boot up.

It could be, that I am on the wrong track regarding the message rewrites to the original queue, but it looks like a good approach with the setSessionTransacted. Are here any Spring JMS Experts that can explain to me how I can implement the three backoff attemtps using the spring-boot framework?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật