Java Spring Boot AMQP 1.3.1.RELEASE-持久队列

Java Spring Boot AMQP 1.3.1.RELEASE-持久队列,java,spring,rabbitmq,amqp,spring-amqp,Java,Spring,Rabbitmq,Amqp,Spring Amqp,出于某些原因,即使我在Spring AMQP队列配置中指定了该设置,我的队列也不会被创建为持久队列: @Bean Queue queue() { //durable queue - true return new Queue(queueName, true); } 我使用Spring AMQP连接到RabbitMQ并在直接交换上侦听该队列 @Bean DirectExchange exchange() { return new DirectExchange(exchan

出于某些原因,即使我在Spring AMQP队列配置中指定了该设置,我的队列也不会被创建为持久队列:

@Bean
Queue queue() {
    //durable queue - true
    return new Queue(queueName, true);
}
我使用Spring AMQP连接到RabbitMQ并在直接交换上侦听该队列

@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;
}

我是否缺少一个配置步骤?

您需要一个
RabbitAdmin
@Bean
来执行声明


它向连接工厂注册自己,并在建立连接时执行声明。

您需要一个
RabbitAdmin
@Bean
来执行声明


它向连接工厂注册自身,并在建立连接时执行声明。

该设置未生效,因为在部署上述代码之前,队列已存在,且不持久。通过管理控制台或CLI删除队列,允许应用程序将队列声明为持久队列(重新启动后)


如果Spring AMQP(RabbitMQ)在队列已声明为不同状态时抛出异常,而不是继续执行无效部署,则会很有帮助。

此设置未生效,因为在部署上述代码之前,队列已存在,且不持久。通过管理控制台或CLI删除队列,允许应用程序将队列声明为持久队列(重新启动后)


如果Spring AMQP(RabbitMQ)在队列已声明为不同状态时抛出异常,而不是继续执行无效的部署,这将非常有帮助。

我将对此进行研究,也可能对上面的第二条评论有所帮助。非常感谢。抱歉-如果正在声明队列,您必须已经有管理员。我们刚刚讨论了你的第二个评论。当前行为是我们几年前添加的一些代码的副作用,这些代码用于自动重新声明在容器运行时删除的队列。现在有一个新设置
不匹配的QueuesFatal
(或将出现在1.6中)。我将对此进行研究,并可能对我上面的第二条评论有所帮助。非常感谢。抱歉-如果正在声明队列,您必须已经有管理员。我们刚刚讨论了你的第二个评论。当前行为是我们几年前添加的一些代码的副作用,这些代码用于自动重新声明在容器运行时删除的队列。现在有一个新设置
不匹配QueuesFatal
(或将在1.6中)。