Vertx amqp client doesnt reconnect on broker down

Viewed 45

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());
                        });
                    }
                }
        );
    }
}
1 Answers

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.

Related