通过 AMQP 1.0 协议连接到 RabbitMQ 持久队列失败 - Protonj2

问题描述 投票:0回答:1

我正在尝试连接我的 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();
    }
}

重要注意事项:

  1. RabbitMQ 中预先声明了队列
  2. 队列配置为持久的,以防止消息丢失
  3. 如果队列的持久属性被删除,消费者连接成功(但这不是有意的)
  4. 需要AMQP 1.0协议才能连接
  5. 用于连接的客户端库是 Apache Qpid Proton J2。
rabbitmq amqp qpid qpid-proton
1个回答
0
投票

您可能需要配置接收方源值以匹配您在代理中创建的队列,以便允许接收方附加。

您需要执行以下操作(配置满足 RabbitMQ 附加先决条件):

ReceiverOptions receiverOptions = new ReceiverOptions();
receiverOptions.sourceOptions().durabilityMode(DurabilityMode.CONFIGURATION);

Receiver receiver = session.openReceiver(address, receiverOptions);
© www.soinside.com 2019 - 2024. All rights reserved.