-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
164 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
FROM openjdk:11-jre-slim | ||
# copy application WAR (with libraries inside) | ||
|
||
COPY target/starter-1.0.0-SNAPSHOT-fat.jar /app.jar | ||
# specify default command | ||
CMD ["java", "-jar", "/app.jar", "-cluster"] | ||
|
||
ENV CLUSTER_PUBLIC_PORT 17001 | ||
ENV CLUSTER_PUBLIC_HOST 192.168.0.100 | ||
|
||
CMD java -jar /app.jar -cluster -cluster-public-port $CLUSTER_PUBLIC_PORT -cluster-public-host $CLUSTER_PUBLIC_HOST -instance 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env sh | ||
|
||
./mvnw clean package -Dmaven.test.skip=true | ||
|
||
java -jar target/starter-1.0.0-SNAPSHOT-fat.jar -cluster -cluster-host 192.168.0.100 -instance 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env sh | ||
|
||
docker rm -f vertx-async-gateway-1 | ||
docker rm -f vertx-async-gateway-2 | ||
|
||
./mvnw clean package -Dmaven.test.skip=true | ||
|
||
docker build -t ananto30/vertx-example:vertx-async-gateway . | ||
docker push ananto30/vertx-example:vertx-async-gateway | ||
|
||
docker run --name vertx-async-gateway-1 -p 8888:8888 -e CLUSTER_PUBLIC_HOST=192.168.0.119 -d ananto30/vertx-example:vertx-async-gateway | ||
docker run --name vertx-async-gateway-2 -p 8889:8888 -e CLUSTER_PUBLIC_HOST=192.168.0.100 -d vertx-async-gateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.ananto.asyncgateway; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.eventbus.EventBus; | ||
import io.vertx.core.eventbus.EventBusOptions; | ||
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author Azizul Haque Ananto | ||
* @since 22/1/21 | ||
*/ | ||
public class DevApp { | ||
|
||
private static final String EVENT_BUS_CLUSTER_PUBLIC_HOST = "192.168.0.100"; // IMPORTANT! for dev, IP of your machine | ||
private static final int EVENT_BUS_CLUSTER_PUBLIC_PORT = 17001; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DevApp.class); | ||
|
||
public static void main(String[] args) { | ||
/* | ||
IMPORTANT!!! | ||
The main method is only used in development mode, when run from intellij or calling the main method directly | ||
*/ | ||
System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory"); | ||
VertxOptions options = new VertxOptions() | ||
.setClusterManager(new HazelcastClusterManager()) // hazlecast is distributed in-memory data grid that can track the distributed clusters | ||
// for kubernetes - https://vertx.io/docs/vertx-hazelcast/java/#_configuring_for_kubernetes | ||
|
||
// this is where all the magic happens :D | ||
// the cluster implementation of the event bus allows different instances to talk with each other through tcp network | ||
// basically it's a distributed event bus now | ||
.setEventBusOptions(new EventBusOptions() | ||
// the most important part! public host can be different for each instance | ||
// for kubernetes we can use the service host most probably | ||
.setClusterPublicHost(EVENT_BUS_CLUSTER_PUBLIC_HOST) | ||
.setClusterPublicPort(EVENT_BUS_CLUSTER_PUBLIC_PORT) | ||
|
||
); | ||
Vertx.clusteredVertx(options, res -> { | ||
if (res.succeeded()) { | ||
Vertx vertx = res.result(); | ||
|
||
// we can deploy multiple verticles using same vertx manager to utilize cores | ||
vertx.deployVerticle(new MainVerticle()); | ||
vertx.deployVerticle(new MainVerticle()); | ||
vertx.deployVerticle(new MainVerticle()); | ||
vertx.deployVerticle(new MainVerticle()); | ||
|
||
EventBus eventBus = vertx.eventBus(); | ||
logger.info("We now have a clustered event bus: " + eventBus); | ||
} else { | ||
logger.error("Failed: {}", res.cause(), res.cause()); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<!-- <pattern>%level [%thread] %logger{0} - %msg%n</pattern>--> | ||
<pattern>%d{yyyy-MM-dd} | %d{HH:mm:ss.SSS} | %-20.20thread | %5p | %-25.25logger{25} | %12(ID: %8mdc{id}) | %m%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="io.netty" level="warn"/> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
</configuration> |