You can't do it if the dead-lettering from alive
is due to expiry - according to the documentation...
It is possible to form a cycle of dead-letter queues. For instance, this can happen when a queue dead-letters messages to the default exchange without specifiying a dead-letter routing key. Messages in such cycles (i.e. messages that reach the same queue twice) will be dropped if the entire cycle is due to message expiry.
(my emphasis).
I just ran a test where the dead-lettering from alive
is due to rejection and it works just fine; after a few cycles, the x-death
header looks like this...
reason: rejected
queue: alive
time: 1419448981
exchange: req
routing-keys: alive
reason: expired
queue: dead
time: 1419448981
exchange: dlx
routing-keys: alive
reason: rejected
queue: alive
time: 1419448976
exchange: req
routing-keys: alive
reason: expired
queue: dead
time: 1419448976
exchange: dlx
routing-keys: alive
...
To test this, I forced a failure in the Spring AMQP listener and set defaultRequeueRejected
to false
.