gpt4 book ai didi

rabbitmq - 到 RabbitMQ 队列的第一条消息导致 channel 关闭

转载 作者:行者123 更新时间:2023-12-05 08:54:16 27 4
gpt4 key购买 nike

发送到我队列的第一条消息总是失败。从第二个开始,一切正常!

Stacktrace

不确定这是否可读:

Created new connection: rabbitConnectionFactory#1b940034:0/SimpleConnection@2c52fbff [delegate=amqp://guest@10.0.0.10:5672/, localPort= 36370]

Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'auto_delete' for exchange 'rabbitmq_exchange' in vhost '/': received 'false' but current is 'true', class-id=40, method-id=10)

我不确定为什么会这样,因为我每次都在新的 VM(AWS EC2 实例)上启动它。 “当前”怎么可能是真的?

我想在 Spring Boot 发布者中配置有问题:

enter image description here

不确定这是否可读:

@Configuration
public class RabbitMqConfig {
@Bean
Queue queue() {
return new Queue(System.getenv("RABBITMQ_QUEUE_NAME"), true,false, false);
}

@Bean
DirectExchange exchange() {
return new DirectExchange(System.getenv("RABBITMQ_EXCHANGE_NAME"), true, false);
}

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

@Bean
public MessageConverter jsonMessageConverter(){
return new Jackson2JsonMessageConverter();
}

public AmqpTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(jsonMessageConverter());
return rabbitTemplate;
}
}

那么这里出了什么问题?谢谢!

最佳答案

错误很明显...

Channel shutdown: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'auto_delete' for exchange 'rabbitmq_exchange' in vhost '/': received 'false' but current is 'true', class-id=40, method-id=10)

当第一次打开连接时,框架会查找队列/绑定(bind)等并声明它们。如果队列已经存在,它必须具有相同的属性/参数。

@Bean
Queue queue() {
return new Queue(System.getenv("RABBITMQ_QUEUE_NAME"), true, false, false);
}

据推测,在消费者方面,它被声明为具有不同的属性......

@Bean
Queue queue() {
return new Queue(System.getenv("RABBITMQ_QUEUE_NAME"), true, false, true);
}

(auto_delete 是不等价的)。

它们必须相同。

关于rabbitmq - 到 RabbitMQ 队列的第一条消息导致 channel 关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485141/

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