首页 > 解决方案 > 引起:com.rabbitmq.client.ShutdownSignalException:通道错误;协议方法:

问题描述

我有一个关于 RabitMQ JAVA Queue 的错误。当我尝试运行消费者客户端时,他向我抛出了这个异常。

Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1107)
at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1075)
at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1059)
at rabbit.consumer.ConsumerDVD.main(ConsumerDVD.java:52)

Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'hello' in vhost '/', class-id=60, method-id=20)
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:361)
    at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1105)
    ... 3 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'hello' in vhost '/', class-id=60, method-id=20)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:484)
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:321)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:554)
    at java.lang.Thread.run(Thread.java:748)

我的部分代码:

public class ConsumerDVD {
    private final static String QUEUE_NAME = "hello";
    private static Writer writer;
    Consumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
                throws IOException {
                DVD dvd = DVD.fromBytes(body);
                System.out.println(" [x] Received '" + dvd.toString() + "'");
                mailService.sendMail("cata1096@yahoo.com","Dvd has been added -- Rabbit!", dvd.toString());
                writeToFile(dvd); 
            }
    };
    channel.basicConsume(QUEUE_NAME, true, consumer);

标签: javarabbitmqqueue

解决方案


推荐阅读