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();
});
}
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);
}
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();
});
}
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);
}
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.");
}
});
});
}
Aggregations