Skip to content

Instantly share code, notes, and snippets.

@league55
Created October 16, 2019 14:28
Show Gist options
  • Save league55/5fcefd9fcadbf19cd8f3166a124de6b6 to your computer and use it in GitHub Desktop.
Save league55/5fcefd9fcadbf19cd8f3166a124de6b6 to your computer and use it in GitHub Desktop.
@Override
public void start(Future<Void> future) throws Exception {
super.start();
NetServerOptions options = new NetServerOptions().setLogActivity(true);
NetServer server = vertx.createNetServer(options);
server.connectHandler(socket -> onInput(configuration, socket))
.listen(configuration.getPort(), configuration.getHost(), connectionStartedHandler(future, configuration));
}
...
private void onInput(Connection configuration, NetSocket socket) {
socket.handler(buffer -> {
String message = buffer.getString(0, buffer.length());
logger.info("Got input: " + message);
EventBus eventBus = vertx.eventBus();
logger.info("Sending message to " + configuration.getProviderAddress() + " : " + message);
eventBus.request(configuration.getProviderAddress(), message, ar -> {
String result = ar.succeeded() ? ar.result().body().toString() : "Error";
logger.info("Received reply: " + result);
socket.write(result);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment