-
Notifications
You must be signed in to change notification settings - Fork 11
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
9 changed files
with
132 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>vertx3-examples</artifactId> | ||
<groupId>nl.revolution</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>basic-eventbus</artifactId> | ||
|
||
<name>Vert.x 3 examples : Basic event bus</name> | ||
|
||
</project> |
27 changes: 27 additions & 0 deletions
27
basic-eventbus/src/main/java/nl/revolution/vertx3/eventbus/basic/EchoServiceVerticle.java
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,27 @@ | ||
package nl.revolution.vertx3.eventbus.basic; | ||
|
||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.core.logging.Logger; | ||
import io.vertx.core.logging.LoggerFactory; | ||
|
||
public class EchoServiceVerticle extends AbstractVerticle { | ||
|
||
public static final String ADDRESS = "echo-service"; | ||
private static final Logger LOG = LoggerFactory.getLogger(EchoServiceVerticle.class); | ||
|
||
@Override | ||
public void start() { | ||
LOG.info("Starting echo-service"); | ||
|
||
vertx.eventBus().consumer(EchoServiceVerticle.ADDRESS, message -> { | ||
JsonObject messageBody = (JsonObject)message.body(); | ||
LOG.info("Received message: " + messageBody); | ||
|
||
messageBody.put("passedThrough", "echo-service"); | ||
LOG.info("Sending reply: " + messageBody); | ||
|
||
message.reply(messageBody); | ||
}); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
basic-eventbus/src/main/java/nl/revolution/vertx3/eventbus/basic/VertxStarter.java
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,22 @@ | ||
package nl.revolution.vertx3.eventbus.basic; | ||
|
||
import io.vertx.core.*; | ||
import io.vertx.core.logging.LoggerFactory; | ||
import io.vertx.core.logging.SLF4JLogDelegateFactory; | ||
|
||
public class VertxStarter extends AbstractVerticle { | ||
|
||
public static void main(String... args) { | ||
System.setProperty(LoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME, SLF4JLogDelegateFactory.class.getName()); | ||
|
||
VertxOptions options = new VertxOptions().setClustered(true).setClusterHost("localhost"); | ||
|
||
Vertx.clusteredVertx(options, resultHandler -> { | ||
Vertx vertx = resultHandler.result(); | ||
vertx.deployVerticle(new EchoServiceVerticle()); | ||
vertx.deployVerticle(new WebVerticle()); | ||
}); | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
basic-eventbus/src/main/java/nl/revolution/vertx3/eventbus/basic/WebVerticle.java
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,32 @@ | ||
package nl.revolution.vertx3.eventbus.basic; | ||
|
||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.core.logging.Logger; | ||
import io.vertx.core.logging.LoggerFactory; | ||
|
||
public class WebVerticle extends AbstractVerticle { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(WebVerticle.class); | ||
|
||
@Override | ||
public void start() { | ||
LOG.info("Starting webVerticle"); | ||
|
||
vertx.createHttpServer().requestHandler(request -> { | ||
JsonObject message = new JsonObject() | ||
.put("text", "Hello world!") | ||
.put("queryString", request.query()); | ||
|
||
LOG.info("Sending message: " + message); | ||
vertx.eventBus().send(EchoServiceVerticle.ADDRESS, message, reply -> { | ||
|
||
JsonObject replyBody = (JsonObject) reply.result().body(); | ||
LOG.info("Received reply: " + replyBody); | ||
|
||
request.response().end(replyBody.encodePrettily()); | ||
}); | ||
|
||
}).listen(8080); | ||
} | ||
} |
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,19 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender" level="INFO"> | ||
<encoder> | ||
<pattern>[%-5level] %logger{15} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="io.vertx" level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="com.hazelcast" level="ERROR"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="io.netty.util.internal.PlatformDependent" level="ERROR"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<root level="INFO"> | ||
</root> | ||
</configuration> |
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
2 changes: 1 addition & 1 deletion
2
...ution/vertx3/eventbus/SimpleVerticle.java → ...ertx3/eventbus/sockjs/SimpleVerticle.java
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
2 changes: 1 addition & 1 deletion
2
...vertx3/eventbus/SockJSEventBusBridge.java → ...eventbus/sockjs/SockJSEventBusBridge.java
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
6 changes: 5 additions & 1 deletion
6
...olution/vertx3/eventbus/VertxStarter.java → .../vertx3/eventbus/sockjs/VertxStarter.java
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