不愿意做出改变 ≈ 坐吃等死!!

JAVA连接rabbitMQ报错解决方法

上一篇 / 下一篇  2017-06-19 16:29:19 / 个人分类:测试工具



报错如下:
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'queue_name' in vhost '/': received 'false' but current is 'true', class-id=50, method-id=10)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.xx;
 
/**
 * Created by xx on 2017/6/19.
 */
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
 
import java.io.IOException;
import java.util.concurrent.TimeoutException;
 
public class SendMQ {
 
    private final static String QUEUE_NAMA="queue_name";
 
    public  static void main(String[] args)
            throws IOException, TimeoutException {
 
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("10.1.1.1");
        factory.setUsername("xx");
        factory.setPassword("xx@123");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAMA,false,false,false,null);
        String message = "hello world";
        channel.basicPublish("",QUEUE_NAMA,null,message.getBytes());
        System.out.println("[x] Send '" + message + "'");
 
        channel.close();
        connection.close();
 
    }
 
}

原因是使用不同的参数定义同一个队列

  channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null);

重复定义

  channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);


第二个参数false改为true即可。



TAG: java JAVA java连接报错

 

评分:0

我来说两句

Open Toolbar