1

I am trying to write a program to pull messages from a message broker via Vert.x AMQP client. I want to make the program try to reconnect on broker down. Currently if I turn off the broker container, the program doesn't react. Below is my code.. What do I miss ?

   public class BrokerConnector {

    public void consumeEventsQueue() {

        AmqpClientOptions options = new AmqpClientOptions()
                .setHost("localhost")
                .setPort(5672)
                .setUsername("")
                .setPassword("");

        AmqpClient amqpClient = AmqpClient.create(options);

        amqpClient.connect(con -> {
            if (con.failed()) {
                System.out.println("Unable to connect to the broker");
            } else {
                System.out.println("Connection succeeded");
            }
        });

        amqpClient.createReceiver("MY_QUEUE",
                done -> {
                    if (done.failed()) {
                        System.out.println("Unable to create receiver");
                    } else {
                        AmqpReceiver receiver = done.result();
                        receiver.handler(msg -> {
                            System.out.println("Received " + msg.bodyAsString());
                        });
                    }
                }
        );
    }
}
  • I faced the same problem and made the following writeup that explains how to create a resilient AMQP Sender: https://github.com/JonasTaulien/vertx-amqp-client-reproducer. Maybe it helps :) – Jonas Taulien Jul 09 '22 at 20:34

1 Answers1

0

To my knowledge (and from peeking at the source) the vertx AMQP client doesn't have automatic client reconnect so it seems quite normal that on loss of connection you application is failing. The client exposes an exception handler that you can hook and recreate your client resources from when the connection drops. There are some clients for AMQP that do have automatic reconnect built in like Qpid JMS or the Qpid protonj2 client.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42