Kanibar
Kanibar

Reputation: 13

RabbitMQ - forward messages to another queue after delete queue with parameter 'x-expires'

I have o problem with rabbitMQ config. I want to forward all messages form queue to another queue 20 minutes after RabbitListener(lost net connection or someone shut down application) is shutdown.

I try do this like this (at spring ):

@Configuration public class RabbitMqConfig { 

    ... 
    @Bean public Queue deadQueue(){ 
        return new Queue("dead_letter_queue", true, false, false);
    }
    
    @Bean
    public Binding deadQueueBinding(){
        Binding binding = new Binding(
                "dead_letter_queue",
                Binding.DestinationType.QUEUE,
                "dlx_exchange",
                "dlx_key",
                null
        );
        return binding;
     }
    ...

}
@Service
public class QueueManagerService {
...
    public void createQueue(String queueName) {
        Map<String, Object> args = new HashMap<>();
        args.put("x-max-priority", 10); 
        args.put("x-expires", 30000);
        args.put("x-dead-letter-exchange", "dlx_exchange");
        args.put("x-dead-letter-routing-key", "dlx_key");
        Binding binding = new Binding(
                queueName,
                Binding.DestinationType.QUEUE,
                "exchange4allQueuesName",
                queueName, //routingKey dajemy ten sam jaki nazwa kolejki
                null
        );
        rabbitAdmin.declareQueue(new Queue(queueName, true, false, false, args));
        rabbitAdmin.declareBinding(binding);
    }
...
}

It seems that parameter 'x-expires' do not work with parameter 'x-dead-letter-exchange' and 'x-dead-letter-routing-key'. I need some sugestions or another way how to forward messages form queue.

I can not and do not want use parameter 'x-message-ttl' on each messages becouse message can wait at queue for consume even 1 hour (consuming one massage takes few secounds)

Upvotes: 0

Views: 371

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

See this doc: https://www.rabbitmq.com/dlx.html

Note that expiration of a queue will not dead letter the messages in it.

So, that's indeed true that we cannot DLX messages from expired queue. Consider to use an x-message-ttl on a queue definition instead of x-expires.

Upvotes: 0

Related Questions