Problem in der Verbindung mit Rabbit MQ
code
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
private final static String QUEUE_NAME = "test";
public static void main(String[] argv) throws java.io.IOException {
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
System.out.println(connection.getPort());
System.out.println(connection.getAddress());
Channel channel = connection.createChannel();
System.out.println("opening channel");
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Bin ich immer die unten Ausnahme:-
1. 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.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
at
com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:844)
at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:61)
at com.in.test.Send.main(Send.java:24) 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 'test' in vhost '/': received 'false' but current is 'true',
class-id=50, method-id=10) 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.AMQChannel.privateRpc(AMQChannel.java:226)
at
com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
... 3 more 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 'test' in vhost '/': received 'false' but current is 'true',
class-id=50, method-id=10) 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:745)
Du musst angemeldet sein, um einen Kommentar abzugeben.
Dies ist passiert, da Sie Ihre bereits vorhandenen Kanal an den RabbitMQ-server mit dem Namen
test
, wurde mit haltbaren Satztrue
:Hast du da geändert, dein code etwa so:
Müssen Sie entfernen Sie den Kanal aus Ihrem server (rabbitmqctl), oder erstellen Sie einen neuen Kanal (eindeutiger name).
Ich würde sagen, deine Antwort dein problem gelöst, da Sie umbenannt in Ihrer Warteschlange, aber Sie hat nicht spiegeln dies in Ihrer Antwort.
Ändern Sie einfach die Zeile
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
zu
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
Dieser arbeitete für mich.
einmal:
1.führen Sie die app, mit der Verbraucher langlebige=true in einem Kanal.queueDeclare
lassen Sie es verbinden Sie die Warteschlange
2.es schließen.
3.starten Sie den producer
nun werden Sie nicht bekommen, diese Ausnahme