Example usage for io.vertx.core Vertx createNetClient

List of usage examples for io.vertx.core Vertx createNetClient

Introduction

In this page you can find the example usage for io.vertx.core Vertx createNetClient.

Prototype

NetClient createNetClient(NetClientOptions options);

Source Link

Document

Create a TCP/SSL client using the specified options

Usage

From source file:com.cyngn.vertx.opentsdb.service.client.OpenTsDbClient.java

License:Apache License

public OpenTsDbClient(String host, int port, Vertx vertx, Consumer<Boolean> onInitialized) {
    NetClientOptions options = new NetClientOptions().setTcpKeepAlive(true);
    netClient = vertx.createNetClient(options);
    connected = false;// ww  w  . ja  v a 2 s  .c om
    consecutiveDisconnects = 0;
    bytesWrittenForPeriod = 0;
    bus = vertx.eventBus();

    this.vertx = vertx;

    this.host = host;
    this.port = port;

    netClient.connect(port, host, connectResult -> {
        onInitialized.accept(connectResult.succeeded());
        if (connectResult.succeeded()) {
            onConnect(connectResult.result());
        } // if we don't succeed initially we'll fail startup of the reporter
    });
}

From source file:examples.NetExamples.java

License:Open Source License

public void example14(Vertx vertx) {

    NetClientOptions options = new NetClientOptions().setConnectTimeout(10000);
    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example15(Vertx vertx) {

    NetClientOptions options = new NetClientOptions().setConnectTimeout(10000);
    NetClient client = vertx.createNetClient(options);
    client.connect(4321, "localhost", res -> {
        if (res.succeeded()) {
            System.out.println("Connected!");
            NetSocket socket = res.result();
        } else {//from   ww  w  . ja v a2  s . co  m
            System.out.println("Failed to connect: " + res.cause().getMessage());
        }
    });
}

From source file:examples.NetExamples.java

License:Open Source License

public void example16(Vertx vertx) {

    NetClientOptions options = new NetClientOptions().setReconnectAttempts(10).setReconnectInterval(500);

    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void exampleNetworkActivityLoggingOnClient(Vertx vertx) {

    NetClientOptions options = new NetClientOptions().setLogActivity(true);

    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example29(Vertx vertx) {
    NetClientOptions options = new NetClientOptions().setSsl(true).setTrustAll(true);
    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example30(Vertx vertx) {
    NetClientOptions options = new NetClientOptions().setSsl(true).setTrustStoreOptions(new JksOptions()
            .setPath("/path/to/your/truststore.jks").setPassword("password-of-your-truststore"));
    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example31(Vertx vertx) {
    Buffer myTrustStoreAsABuffer = vertx.fileSystem().readFileBlocking("/path/to/your/truststore.jks");
    NetClientOptions options = new NetClientOptions().setSsl(true).setTrustStoreOptions(
            new JksOptions().setValue(myTrustStoreAsABuffer).setPassword("password-of-your-truststore"));
    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example32(Vertx vertx) {
    NetClientOptions options = new NetClientOptions().setSsl(true).setPfxTrustOptions(new PfxOptions()
            .setPath("/path/to/your/truststore.pfx").setPassword("password-of-your-truststore"));
    NetClient client = vertx.createNetClient(options);
}

From source file:examples.NetExamples.java

License:Open Source License

public void example33(Vertx vertx) {
    Buffer myTrustStoreAsABuffer = vertx.fileSystem().readFileBlocking("/path/to/your/truststore.pfx");
    NetClientOptions options = new NetClientOptions().setSsl(true).setPfxTrustOptions(
            new PfxOptions().setValue(myTrustStoreAsABuffer).setPassword("password-of-your-truststore"));
    NetClient client = vertx.createNetClient(options);
}