Search in sources :

Example 11 with NetServerOptions

use of io.vertx.core.net.NetServerOptions in project java-chassis by ServiceComb.

the class TcpServer method init.

public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddress> callback) {
    NetServer netServer;
    if (endpointObject.isSslEnabled()) {
        SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(sslKey, null);
        SSLOption sslOption;
        if (factory == null) {
            sslOption = SSLOption.buildFromYaml(sslKey);
        } else {
            sslOption = factory.createSSLOption();
        }
        SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass());
        NetServerOptions serverOptions = new NetServerOptions();
        VertxTLSBuilder.buildNetServerOptions(sslOption, sslCustom, serverOptions);
        netServer = vertx.createNetServer(serverOptions);
    } else {
        netServer = vertx.createNetServer();
    }
    netServer.connectHandler(netSocket -> {
        TcpServerConnection connection = createTcpServerConnection();
        connection.init(netSocket);
    });
    InetSocketAddress socketAddress = endpointObject.getSocketAddress();
    netServer.listen(socketAddress.getPort(), socketAddress.getHostString(), ar -> {
        if (ar.succeeded()) {
            callback.success(socketAddress);
            return;
        }
        String msg = String.format("listen failed, address=%s", socketAddress.toString());
        callback.fail(new Exception(msg, ar.cause()));
    });
}
Also used : SSLOptionFactory(io.servicecomb.foundation.ssl.SSLOptionFactory) InetSocketAddress(java.net.InetSocketAddress) NetServerOptions(io.vertx.core.net.NetServerOptions) NetServer(io.vertx.core.net.NetServer) SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom)

Example 12 with NetServerOptions

use of io.vertx.core.net.NetServerOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest method before.

@Before
public void before(TestContext context) {
    vertx = Vertx.vertx();
    final Async async = context.async();
    vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
    vertx.eventBus().consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
    vertx.setPeriodic(1000, __ -> vertx.eventBus().send("ping", new JsonObject().put("value", "hi")));
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("test")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("ping")), new NetServerOptions(), event -> eventHandler.handle(event));
    bridge.listen(7000, res -> {
        context.assertTrue(res.succeeded());
        async.complete();
    });
}
Also used : Message(io.vertx.core.eventbus.Message) Async(io.vertx.ext.unit.Async) NetServerOptions(io.vertx.core.net.NetServerOptions) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Before(org.junit.Before)

Aggregations

NetServerOptions (io.vertx.core.net.NetServerOptions)12 NetServer (io.vertx.core.net.NetServer)9 NetSocket (io.vertx.core.net.NetSocket)7 Handler (io.vertx.core.Handler)6 Vertx (io.vertx.core.Vertx)6 Buffer (io.vertx.core.buffer.Buffer)6 Pump (io.vertx.core.streams.Pump)6 NetClient (io.vertx.core.net.NetClient)3 NetClientOptions (io.vertx.core.net.NetClientOptions)2 Test (org.junit.Test)2 SSLCustom (io.servicecomb.foundation.ssl.SSLCustom)1 SSLOption (io.servicecomb.foundation.ssl.SSLOption)1 SSLOptionFactory (io.servicecomb.foundation.ssl.SSLOptionFactory)1 VertxOptions (io.vertx.core.VertxOptions)1 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)1 Message (io.vertx.core.eventbus.Message)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 JsonObject (io.vertx.core.json.JsonObject)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1