Search in sources :

Example 51 with ProtonClient

use of io.vertx.proton.ProtonClient in project vertx-examples by vert-x3.

the class ReconnectSender method setupConnection.

private void setupConnection(ProtonClient client) {
    String peer = connectionControl.nextPeer();
    System.out.println("Attempting to connect to peer: " + peer);
    String[] peerDetails = peer.split(":");
    client.connect(peerDetails[0], Integer.parseInt(peerDetails[1]), res -> {
        if (!res.succeeded()) {
            System.out.println("Connect failed: " + res.cause());
            handleConnectionFailure(client, null, false);
            return;
        }
        ProtonConnection connection = res.result();
        conn = connection;
        connection.openHandler(x -> {
            connectionControl.connected();
            setupSender(connection);
        }).closeHandler(x -> {
            handleConnectionFailure(client, connection, true);
        }).disconnectHandler(x -> {
            handleConnectionFailure(client, connection, false);
        }).open();
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) AbstractVerticle(io.vertx.core.AbstractVerticle) Vertx(io.vertx.core.Vertx) ProtonSender(io.vertx.proton.ProtonSender) Message(org.apache.qpid.proton.message.Message) ProtonClient(io.vertx.proton.ProtonClient) Instant(java.time.Instant) Runner(io.vertx.example.util.Runner) ProtonConnection(io.vertx.proton.ProtonConnection)

Example 52 with ProtonClient

use of io.vertx.proton.ProtonClient in project vertx-examples by vert-x3.

the class ReconnectSender method start.

@Override
public void start() throws Exception {
    ProtonClient client = ProtonClient.create(vertx);
    setupConnection(client);
}
Also used : ProtonClient(io.vertx.proton.ProtonClient)

Example 53 with ProtonClient

use of io.vertx.proton.ProtonClient in project vertx-examples by vert-x3.

the class ReconnectReceiver method setupConnection.

private void setupConnection(ProtonClient client) {
    String peer = connectionControl.nextPeer();
    System.out.println("Attempting to connect to peer: " + peer);
    String[] peerDetails = peer.split(":");
    client.connect(peerDetails[0], Integer.parseInt(peerDetails[1]), res -> {
        if (!res.succeeded()) {
            System.out.println("Connect failed: " + res.cause());
            handleConnectionFailure(client, null, false);
            return;
        }
        ProtonConnection connection = res.result();
        connection.openHandler(x -> {
            connectionControl.connected();
            setupReceiver(connection);
        }).closeHandler(x -> {
            handleConnectionFailure(client, connection, true);
        }).disconnectHandler(x -> {
            handleConnectionFailure(client, connection, false);
        }).open();
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonReceiver(io.vertx.proton.ProtonReceiver) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) AbstractVerticle(io.vertx.core.AbstractVerticle) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) Instant(java.time.Instant) Runner(io.vertx.example.util.Runner) ProtonConnection(io.vertx.proton.ProtonConnection)

Example 54 with ProtonClient

use of io.vertx.proton.ProtonClient in project vertx-examples by vert-x3.

the class ReconnectReceiver method start.

@Override
public void start() throws Exception {
    ProtonClient client = ProtonClient.create(vertx);
    setupConnection(client);
}
Also used : ProtonClient(io.vertx.proton.ProtonClient)

Example 55 with ProtonClient

use of io.vertx.proton.ProtonClient in project vertx-examples by vert-x3.

the class Sender method start.

@Override
public void start() throws Exception {
    ProtonClient client = ProtonClient.create(vertx);
    client.connect("localhost", 5672, res -> {
        if (!res.succeeded()) {
            System.out.println("Connect failed: " + res.cause());
            return;
        }
        ProtonConnection connection = res.result();
        connection.open();
        ProtonSender sender = connection.createSender(address);
        // Can optionally add an openHandler and/or sendQueueDrainHandler
        // to await remote sender open completing and credit to send being
        // granted. Here we will just schedule sends to happen if there
        // is credit at the time.
        sender.open();
        // Schedule sending of a message every second
        System.out.println("Sender created, scheduling sends.");
        vertx.setPeriodic(1000, x -> {
            if (!sender.sendQueueFull()) {
                final int msgNum = sent.incrementAndGet();
                Message message = message("Hello " + msgNum);
                sender.send(message, delivery -> {
                    System.out.println(String.format("Message " + msgNum + " was received by the server: remote state=%s", delivery.getRemoteState()));
                });
                System.out.println("Sent message: " + msgNum);
            } else {
                System.out.println("No credit to send, waiting.");
            }
        });
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) ProtonSender(io.vertx.proton.ProtonSender) Message(org.apache.qpid.proton.message.Message) ProtonClient(io.vertx.proton.ProtonClient)

Aggregations

ProtonClient (io.vertx.proton.ProtonClient)55 ProtonConnection (io.vertx.proton.ProtonConnection)42 Handler (io.vertx.core.Handler)27 Message (org.apache.qpid.proton.message.Message)27 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)24 AsyncResult (io.vertx.core.AsyncResult)23 Test (org.junit.Test)22 Arrays (java.util.Arrays)21 ProtonHelper.message (io.vertx.proton.ProtonHelper.message)20 ProtonStreams (io.vertx.proton.streams.ProtonStreams)20 Section (org.apache.qpid.proton.amqp.messaging.Section)20 Async (io.vertx.ext.unit.Async)19 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 Logger (io.vertx.core.impl.logging.Logger)18 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)18 TestContext (io.vertx.ext.unit.TestContext)18 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)18 FutureHandler (io.vertx.proton.FutureHandler)18 MockServerTestBase (io.vertx.proton.MockServerTestBase)18