我正在尝试连接我的 AMQP 1.0 使用者(使用 Apache ProtonJ2 库)。但我的连接失败并出现以下错误
org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException: PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'test_queue_durable' in vhost '/': received 'false' but current is 'true' [condition = amqp:precondition-failed]
以下是我的示例代码。
public void connectAmqp() throws Throwable {
final String serverHost = "localhost";
final int serverPort = 5672;
final String address = "test_queue_durable";
final Client client = Client.create();
final ConnectionOptions options = new ConnectionOptions().user("admin").password("admin");
try{
Connection connection = client.connect(serverHost, serverPort, options);
Receiver receiver = connection.openReceiver(address);
for (int i = 0; i < 100; ++i) {
Delivery delivery = receiver.receive();
System.out.println(delivery.message().body().getClass());
System.out.println("*-*-*-* " + new String((byte[])delivery.message().body()));
}
}catch (Exception e) {
e.printStackTrace();
}
}
重要注意事项:
您可能需要配置接收方源值以匹配您在代理中创建的队列,以便允许接收方附加。
您需要执行以下操作(配置满足 RabbitMQ 附加先决条件):
ReceiverOptions receiverOptions = new ReceiverOptions();
receiverOptions.sourceOptions().durabilityMode(DurabilityMode.CONFIGURATION);
Receiver receiver = session.openReceiver(address, receiverOptions);