rabbitmq 学习-错误总结
1,bind时候出错
// 定义一个queue,durable(即rabbitmq重启后也不会消失)
DeclareOk queueDeclare = channel.queueDeclare("test.queue", true)
channel.exchangeDeclare( "test.exchange", "direct");
channel.queueBind("test.queue", "test.exchange", "test.routingkey");
//上面如果定义一个 durability 的queue,就会出现异常
java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:121)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:139)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:502)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:512)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:70)
at TestSender.sendMsg(TestSender.java:67)
at TestSender.main(TestSender.java:85)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: {#method<connection.close>(reply-code=530,reply-text=NOT_ALLOWED - durability settings of queue 'test.queue' in vhost '/' incompatible with exchange 'test.exchange' in vhost '/',class-id=50,method-id=20),null,""}
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:81)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:47)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:336)
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:209)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:133)
... 5 more
根据提示,找到了原因,如果定义一durable的queue,那么bind此queue的exchange也必须是durable的,解决办法
1,channel.queueDeclare(queue, true); channel.exchangeDeclare(exchange, "direct", true);
2,channel.queueDeclare(queue); channel.exchangeDeclare(exchange, "direct");
// 定义一个queue,durable(即rabbitmq重启后也不会消失)
DeclareOk queueDeclare = channel.queueDeclare("test.queue", true)
channel.exchangeDeclare( "test.exchange", "direct");
channel.queueBind("test.queue", "test.exchange", "test.routingkey");
//上面如果定义一个 durability 的queue,就会出现异常
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:121)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:139)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:502)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:512)
at com.rabbitmq.client.impl.ChannelN.queueBind(ChannelN.java:70)
at TestSender.sendMsg(TestSender.java:67)
at TestSender.main(TestSender.java:85)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: {#method<connection.close>(reply-co
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:81)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:47)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:336)
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:209)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:133)
... 5 more
根据提示,找到了原因,如果定义一durable的queue,那么bind此queue的exchange也必须是durable的,解决办法
1,channel.queueDeclare(queue, true); channel.exchangeDeclare(exchange, "direct", true);
2,channel.queueDeclare(queue); channel.exchangeDeclare(exchange, "direct");