Home > Mobile >  Spring AMQP: remove old bindings and queues
Spring AMQP: remove old bindings and queues

Time:03-22

I’m using Spring AMQP and Spring Boot @Configuration and @Bean annotations in order to create all required queues, exchanges and bindings.

@Bean
public Queue queue() {
    return new Queue("my_old_queue", true, false, false);
}

@Bean
public Exchange exchange() {
    return new DirectExchange("MY_OLD_EXCHANGE");
}

@Bean
public Binding binding() {
    return BindingBuilder.bind(queue())
                         .to(exchange())
                         .with("old_binding")
                         .noargs();
}

But I’ve faced with a problem of upgrading my topology:

  1. I wanna add a new queue/binding/exchange
  2. And remove an old queue/binding/exchange (even if it was durable entity).

Does some annotation exists for removing or unbinding (like @Unbind)? I’ve seen the example where RabbitManagementTemplate was suggested, but it’s a completely different way of configuration - I wanna keep everything in the single @Configuration class and use annotations or config beans only (is it possible?). Does some common pattern exists for creating/removing and updating rabbit topology (maybe I missed something)?

CodePudding user response:

You cannot delete entities with annotations or configuration, use the RabbitAdmin.delete*() methods to remove them like in that answer - the management template was used to list the bindings, the RabbitAdmin (amqpAdmin) does the removals.

  • Related