forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumerVerticle.java
More file actions
32 lines (26 loc) Β· 975 Bytes
/
ConsumerVerticle.java
File metadata and controls
32 lines (26 loc) Β· 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package verticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.core.json.JsonObject;
public class ConsumerVerticle extends AbstractVerticle {
private String verticleAddress = "Consumer";
private EventBus eventBus;
@Override
public void start() throws Exception {
assignEventBus();
registerHandler();
}
private void assignEventBus() {
eventBus = vertx.eventBus();
}
private void registerHandler() {
MessageConsumer<JsonObject> messageConsumer = eventBus.consumer(verticleAddress);
messageConsumer.handler(message -> {
JsonObject jsonMessage = message.body();
System.out.println(jsonMessage.getValue("message_from_sender_verticle"));
JsonObject jsonReply = new JsonObject().put("reply", "how interesting!");
message.reply(jsonReply);
});
}
}