I would like to have a Retry Policy only on a specific listener that listen to a specific queue (DLQ in the specific case).
@RabbitListener(queues = "my_queue_dlq", concurrency = "5")
public void listenDLQ(Message dlqMessage) {
// here implement logic for resend message to original queue (my_queue) for n times with a certain interval, and after n times... push to the Parking Lot Queue
}
BUT if I am not misunderstood when I specify a Retry Policy (for ex. on the application.yaml) all @RabbitListeners use it.
I suppose the only way would be to create a dedicated container factory, but this last one would be identical to the default one with ONLY one more Retry policy ... and it doesn't seem to me like the best to do so.
Something like that :
@RabbitListener(containerFactory = "container-factory-with-retrypolicy", queues = "myDLQ", concurrency = "5")
public void listenDLQ(Message dlqMessage) {
// here implement logic for resend message to original queues for n times with a certain interval
}
Do you see alternatives ?
Thank you in advance.
The ListenerContainer
instances are registered to the RabbitListenerEndpointRegistry
. You can obtain a desired one by the @RabbitListener(id)
value. There you can get access to the MessageListener
(casting to the AbstractAdaptableMessageListener
) and set its retryTemplate
property.
Or you can implement a ContainerCustomizer<AbstractMessageListenerContainer>
, check its getListenerId()
and do the same manipulation against its getMessageListener()
.