java - Spring AMQP @RabbitListener custom retry on business error best practice -


following scenario: have @rabbitlistener picking messages rabbitmq. message runs error because can not find related business object. in case have no possibility reply sender want ignore message after amount of retry.

my solution: in @rabbitlistener whenever not possible find business object throw custom runtime exception. in configuraion have retryoperationsinterceptor max attempts , custom recoverer.

what best practice handling such cases? can configure diffrent recoverer class when having more 1 @rabbitlistener?

see configuraion:

@bean public simplerabbitlistenercontainerfactory rabbitlistenercontainerfactory() {     simplerabbitlistenercontainerfactory factory = new simplerabbitlistenercontainerfactory();     factory.setmessageconverter(new custommessageconverter());     factory.setconnectionfactory(connectionfactory());     factory.setacknowledgemode(acknowledgemode.auto);     factory.setconcurrentconsumers(1);     factory.setmaxconcurrentconsumers(20);      advice[] advicechain = new advice[] { interceptor() };     factory.setadvicechain(advicechain);     return factory; }  @bean retryoperationsinterceptor interceptor() {     return retryinterceptorbuilder.stateless()             .maxattempts(5)             .recoverer(new customrejectandrecoverer())             .build(); } 

and customrejectandrecoverer

public class customrejectandrecoverer implements messagerecoverer {  @override public void recover(message message, throwable cause) {     if (exceptionutils.getrootcause(cause) instanceof businessobjectnotfoundruntimeexception) {         throw new listenerexecutionfailedexception("retry policy exhausted",                 new amqprejectanddontrequeueexception(cause), message);     } } 

}

you need different container factory each different retry configuration.

in 2.0, have added new errorhandler attribute annotation each listener can have customized error handler, regardless of container factory created by.

this in first milestone release; current milestone m2 , m3 out shortly. ga release expected in june.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -