gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:00:44 39 4
gpt4 key购买 nike

由于某种原因,即使我在 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;
}

我是否缺少配置步骤?

最佳答案

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

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

关于java - Spring-Boot AMQP 1.3.1.RELEASE - 持久队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34950510/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com