channel error:reply-code=404, reply-text=NOT_FOUND - no exchange ‘console‘ in vhost ‘/‘, class-id=40

1、 错误信息

at com.feng.rabbitmq.six.ReceiveLogsDirect01.main(ReceiveLogsDirect01.java:31)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'console' in vhost '/', class-id=40, method-id=30)
	at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)

2、 错误原因

绑定交换机这里应该使用 channel.queueBind("console",EXCHANGE_NAME,"info");但是我却使用的是 channel.exchangeBind(queueName,EXCHANGE_NAME,"info");

3、错误源文件 ReceiveLogs.java

package com.feng.rabbitmq.six;

import com.feng.rabbitmq.utiils.RabbitMQUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * 消费者接收消息
 * 2021-12-10 09:54
 */
public class ReceiveLogsDirect01 {
    public static final String EXCHANGE_NAME = "direct_logs";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        /**
         * Caused by: com.rabbitmq.client.ShutdownSignalException:
         * channel error; protocol method: #method<channel.close>(reply-code=404,
         * reply-text=NOT_FOUND - no exchange 'console' in vhost '/', class-id=40, method-id=30)
         */
        channel.queueDeclare("console", false, false, false, null);
//        String queueName = channel.queueDeclare().getQueue();
        //交换机和队列绑定
//        channel.exchangeBind("console",EXCHANGE_NAME,"info");
        channel.queueBind("console",EXCHANGE_NAME,"info");
//        channel.exchangeBind(queueName,EXCHANGE_NAME,"info");
        channel.exchangeBind("console",EXCHANGE_NAME,"warning");

        //接收消息
        DeliverCallback deliverCallback = (consumerTag,message) -> {
            System.out.println("ReceiveLogsDirect01控制台打印接收到的消息:"+new String(message.getBody(),"utf-8"));
        };
        channel.basicConsume("console",true,deliverCallback,consumerTag -> {
            System.out.println("消费者取消消息时回调");
        });
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值