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