use of io.vertx.core.net.NetClient in project vertx-proton by vert-x3.
the class ProtonClientImpl method connect.
public void connect(ProtonClientOptions options, String host, int port, String username, String password, Handler<AsyncResult<ProtonConnection>> handler) {
final NetClient netClient = vertx.createNetClient(options);
connectNetClient(netClient, host, port, username, password, new ConnectCompletionHandler(handler, netClient), options);
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeInteropTest method testSendMessageWithReplyBacktrack.
@Test
public void testSendMessageWithReplyBacktrack(TestContext context) {
// Send a request and get a response
NetClient client = vertx.createNetClient();
final Async async = context.async();
client.connect(7000, "localhost", conn -> {
context.assertFalse(conn.failed());
NetSocket socket = conn.result();
final FrameParser parser = new FrameParser(parse -> {
context.assertTrue(parse.succeeded());
JsonObject frame = parse.result();
context.assertNotEquals("err", frame.getString("type"));
context.assertEquals("Hello vert.x", frame.getJsonObject("body").getString("value"));
client.close();
async.complete();
});
socket.handler(parser);
FrameHelper.sendFrame("send", "hello", "#backtrack", new JsonObject().put("value", "vert.x"), socket);
});
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeInteropTest method testRegister.
@Test
public void testRegister(TestContext context) {
// Send a request and get a response
NetClient client = vertx.createNetClient();
final Async async = context.async();
client.connect(7000, "localhost", conn -> {
context.assertFalse(conn.failed());
NetSocket socket = conn.result();
// 1 reply will arrive
// MESSAGE for echo
final FrameParser parser = new FrameParser(parse -> {
context.assertTrue(parse.succeeded());
JsonObject frame = parse.result();
context.assertNotEquals("err", frame.getString("type"));
context.assertEquals("Vert.x", frame.getJsonObject("body").getString("value"));
client.close();
async.complete();
});
socket.handler(parser);
FrameHelper.sendFrame("register", "echo", null, socket);
// now try to publish a message so it gets delivered both to the consumer registred on the startup and to this
// remote consumer
FrameHelper.sendFrame("publish", "echo", new JsonObject().put("value", "Vert.x"), socket);
});
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeTest method testSendMessageWithReplyBacktrackTimeout.
@Test
public void testSendMessageWithReplyBacktrackTimeout(TestContext context) {
// Send a request and get a response
NetClient client = vertx.createNetClient();
final Async async = context.async();
// This does not reply and will provoke a timeout
vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> {
/* Nothing! */
});
client.connect(7000, "localhost", context.asyncAssertSuccess(socket -> {
final FrameParser parser = new FrameParser(parse -> {
context.assertTrue(parse.succeeded());
JsonObject frame = parse.result();
context.assertEquals("err", frame.getString("type"));
context.assertEquals("TIMEOUT", frame.getString("failureType"));
context.assertEquals(-1, frame.getInteger("failureCode"));
context.assertEquals("#backtrack", frame.getString("address"));
client.close();
async.complete();
});
socket.handler(parser);
JsonObject headers = new JsonObject().put("timeout", 100L);
FrameHelper.sendFrame("send", "test", "#backtrack", headers, null, new JsonObject().put("value", "vert.x"), socket);
}));
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeTest method testSendVoidStringMessage.
@Test
public void testSendVoidStringMessage(TestContext context) {
// Send a request and get a response
NetClient client = vertx.createNetClient();
final Async async = context.async();
vertx.eventBus().consumer("test", (Message<Object> msg) -> {
context.assertTrue(msg.body() instanceof String);
context.assertEquals("I'm not a JSON Object", msg.body());
client.close();
async.complete();
});
client.connect(7000, "localhost", context.asyncAssertSuccess(socket -> {
FrameHelper.sendFrame("send", "test", "I'm not a JSON Object", socket);
}));
}
Aggregations