Don't fork me!

Travis CI status: Build Status

1. Introduction

build, run and test
./gradlew
bash -c 'PORT=8080 ./build/install/vertx-hazelcast/bin/vertx-hazelcast &'
bash -c 'PORT=8081 ./build/install/vertx-hazelcast/bin/vertx-hazelcast &'
app
@Slf4j
public class App {

  static final String ADDR = "127.0.0.1";
  static final ObjectMapper mapper = new ObjectMapper();
  static final String PORT = System.getenv().getOrDefault("PORT", "8080");
  static final int port = Integer.valueOf(PORT);

  public static void main(String[] args) {
    final HazelcastClusterManager clusterManager = new HazelcastClusterManager();
    final VertxOptions options = new VertxOptions().setClusterManager(clusterManager);

    Vertx.clusteredVertx(options, result -> {
      if (result.failed()) {
        log.info("result failed");
        return;
      }

      final Vertx vertx = result.result();
      final EventBus eventBus = vertx.eventBus();
      final HttpServer server = vertx.createHttpServer();
      final MessageConsumer<String> consumer = eventBus.consumer(ADDR);

      consumer.handler(message -> {
        final String body = message.body();
        final JsonObject jsonObject = new JsonObject(body);
        final String jsonString = jsonObject.encode();
        log.info("msg-{} in: {}", port, jsonString);
      });

      server.requestHandler(request -> {
        request.bodyHandler(body -> {
          final JsonObject jsonObject = body.toJsonObject();
          final String jsonString = jsonObject.encode();
          log.info("http-{} in: {}", port, jsonString);
          eventBus.send(ADDR, jsonString);
          request.response()
                 .putHeader("Content-Type", "application/json")
                 .end(jsonString);
        });
      });

      server.listen(port, event -> {
        log.info("listening {} port.", port);
      });
    });
  }
}

Initially generated by using generator-jvm yeoman generator (java-vertx)

2. Implementation

TODO: implement documentation…​