Search code examples
springrabbitmqamqpspring-rabbit

Spring AMPQ - Create Queue Bean with expiration


How should I create a RabbitMQ Queue as a annotation based Bean with message expiration set? The following code does not seem to work.

    @Bean()
public Queue theQueue(){
    Map<String, Object> args = new HashMap<>();
    args.put("x-message-ttl", "60000");
    return new Queue(MessageConstants.QUEUE, true, false, false, args);
}

It creates a Queue alright but does not have the expiration set for the message


Solution

  • It needs to be a numeric value; try

    args.put("x-message-ttl", 60000);
    

    If the queue already exists with no arguments; you'll need to delete it first.