0

For some reason my queue is not created as durable even though I specify that setting within the Spring AMQP Queue configuration:

@Bean
Queue queue() {
    //durable queue - true
    return new Queue(queueName, true);
}

I am the using Spring AMQP to connect to RabbitMQ and listen to that Queue on a Direct Exchange.

@Bean
DirectExchange exchange() {
    return new DirectExchange(exchangeName);
}

@Bean
Binding binding(Queue queue, DirectExchange exchange) {
    return BindingBuilder.bind(queue).to(exchange).with(queueName);
}

@Bean
public ConnectionFactory connectionFactory() {

    CloudFactory cloudFactory = new CloudFactory();
    Cloud cloud = cloudFactory.getCloud();

    AmqpServiceInfo serviceInfo = (AmqpServiceInfo) 
            cloud.getServiceInfo(serviceName);

    CachingConnectionFactory connectionFactory =
        new CachingConnectionFactory(serviceInfo.getHost());
    connectionFactory.setUsername(serviceInfo.getUserName());
    connectionFactory.setPassword(serviceInfo.getPassword());
    connectionFactory.setVirtualHost(serviceInfo.getVirtualHost());
    return connectionFactory;
}

@Bean
MessageListenerAdapter underwritingMessageListener() throws Exception {
    return new MessageListenerAdapter(new UnderwritingMessageListener()) {{
        setDefaultListenerMethod("onMessage");
    }};
}

@Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, 
        MessageListenerAdapter underwritingMessageListener) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(queueName);
    container.setMessageListener(underwritingMessageListener);
    return container;
}

Am I missing a configuration step?

Jeremy Deane
  • 131
  • 1
  • 6

2 Answers2

2

The setting did not take effect because the Queue already existed, as non-durable, prior to deploying the code above. Deleting the Queue, via the management console or CLI, allowed the application to declare the Queue as durable (after reboot).

It would be helpful if Spring-AMQP (RabbitMQ) threw an exception when a Queue was already declared in a different state rather than proceeding with an invalid deployment.

Jeremy Deane
  • 131
  • 1
  • 6
0

You need a RabbitAdmin @Bean to do the declarations.

It registers itself with the connection factory and performs the declarations when the connection is established.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I will look into this as well as it may help with my second comment above. Thank you very much. – Jeremy Deane Jan 22 '16 at 16:36
  • Sorry - you must already have an admin if the queue is being declared. We just addressed your second comment [JIRA Here](https://jira.spring.io/browse/AMQP-562). The current behavior is a side-effect of some code we added a couple of years ago to automatically redeclare queues that are deleted while the container is running. There is now a new setting `mismatchedQueuesFatal` (or will be in 1.6). – Gary Russell Jan 22 '16 at 16:40