spring-amqp icon indicating copy to clipboard operation
spring-amqp copied to clipboard

Make RepublishMessageRecoverer.prefixedOriginalRoutingKey protected instead of private

Open bastiat opened this issue 4 years ago • 1 comments

Enhancement

Hello,

How do you find idea of making String RepublishMessageRecoverer.prefixedOriginalRoutingKey protected instead of private? It would make if possible to override prefixedOriginalRoutingKey to send back with different routing key depending on message.

My case is I would like to add custom headers to message that is moved to DLQ (x-dead-letter-exchange) that is associated with a queue. RejectAndDontRequeueRecoverer would be fine, but I can't add custom headers there. RepublishMessageRecoverer is good for headers, but it sends back to wrong exchange - I would like to make it behave the same as RejectAndDontRequeueRecoverer about used DLQ/exchange. Now I will have to override whole recover() with copy paste and write custom private prefixedOriginalRoutingKey. If prefixedOriginalRoutingKey were protected, it would be sufficient to override it without necessity of copy-paste recover() and other private methods used by it.

I would like to:

@Override
protected String prefixedOriginalRoutingKey(Message message) {
            return message.getMessageProperties().getConsumerQueue() + ".dead.letter";
}

Regarding what @garyrussell wrote but making that method protected won't change the exchange - you can set the errorExchangeName for that (also errorRoutingKey and then the prefix won't be used).

It seems to me that I can't get what I need with errorExchangeName or errorRoutingKey - they are static and I need to compute DLQ dynamically. If it do is possible, please show how could I implement it.

Thanks and Regards.

bastiat avatar Nov 02 '21 09:11 bastiat

I am fine with making it protected; my comment was related to this...

is good for headers, but it sends back to wrong exchange

...there is (currently) no mechanism to choose a different exchange at runtime.

Feel free to submit a PR with the changes you need.

garyrussell avatar Nov 02 '21 13:11 garyrussell