ConnectionFactory connectionFactory = ctx.getBean(ConnectionFactory.class);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
container.setMessageListener(new MessageListenerAdapter(new POJO()));
container.setQueueNames("retry.test.queue");
StatefulRetryOperationsInterceptorFactoryBean fb = new StatefulRetryOperationsInterceptorFactoryBean();
// use an external template so we can share his cache
RetryTemplate retryTemplate = new RetryTemplate();
RetryContextCache cache = new MapRetryContextCache();
retryTemplate.setRetryContextCache(cache);
fb.setRetryOperations(retryTemplate);
// give him a reference to the retry cache so he can clean it up
MissingMessageIdAdvice missingIdAdvice = new MissingMessageIdAdvice(cache);
Advice retryInterceptor = fb.getObject();
// add both advices
container.setAdviceChain(new Advice[] {missingIdAdvice, retryInterceptor});
container.start();
template.convertAndSend("retry.test.exchange", "retry.test.binding", "Hello, world!");