SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(template.getConnectionFactory());
MessageListenerAdapter messageListener = new MessageListenerAdapter();
messageListener.setDelegate(new Object());
container.setMessageListener(messageListener);
RabbitAdmin admin = new RabbitAdmin(template.getConnectionFactory());
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-dead-letter-exchange", "test.DLE");
Queue queue = new Queue("", false, false, true, args);
String testQueueName = admin.declareQueue(queue);
// Create a DeadLetterExchange and bind a queue to it with the original routing key
DirectExchange dle = new DirectExchange("test.DLE", false, true);
admin.declareExchange(dle);
Queue dlq = new AnonymousQueue();
admin.declareQueue(dlq);
admin.declareBinding(BindingBuilder.bind(dlq).to(dle).with(testQueueName));
container.setQueueNames(testQueueName);
container.afterPropertiesSet();
container.start();