问题描述
使用 Typescript 3.9.7
和 amqplib 0.6.0
。今天在 Amazon MQ 中创建新的代理。但是当我尝试连接到 Rabbit 并断言交换和队列时,我看到了这个错误。
Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no queue 'QUEUE-NAME' in vhost '/'"
这是代码
const rabbitMQParams: { connection: amqplib.Connection | null } = {
connection: null,};
const connectRabbitMq = async () => {
const options: amqplib.Options.Connect = { protocol,hostname: host,port: +port!,username: user,password };
// protocol and other variables are correct
rabbitMQParams.connection = await amqplib.connect(options);
}
const setConnectionAndChannel = async (job: WorkTypes) => {
if (!rabbitMQParams.connection) {
await connectRabbitMq();
}
if (!this.channel) {
this.channel = await rabbitMQParams.connection!.createChannel();
}
const isExchangeExists: Replies.Empty = await this.channel.checkExchange(WorkQueueHelper.exchange);
if (!isExchangeExists) {
await this.channel.assertExchange(WorkQueueHelper.exchange,'direct',{ durable: durableExchanges });
}
const queueName: string = 'QUEUE-NAME';
const isQueueExists: Replies.Empty = await this.channel.checkQueue(queueName)
if (!isQueueExists) {
await this.channel.assertQueue(queueName,{ durable: durableQueues,autoDelete: false });
}
await this.channel.bindQueue(queueName,WorkQueueHelper.exchange,job);
}
网上没有找到什么好的教程来避免这个错误。请帮帮我
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)