-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
LocalReceiver.java
30 lines (24 loc) · 999 Bytes
/
LocalReceiver.java
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
package io.vertx.example.core.eventbus.messagecodec;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
import io.vertx.example.core.eventbus.messagecodec.util.CustomMessage;
/**
* Local receiver
* @author Junbong
*/
public class LocalReceiver extends AbstractVerticle {
@Override
public void start() throws Exception {
EventBus eventBus = getVertx().eventBus();
// Does not have to register codec because sender already registered
/*eventBus.registerDefaultCodec(CustomMessage.class, new CustomMessageCodec());*/
// Receive message
eventBus.consumer("local-message-receiver", message -> {
CustomMessage customMessage = (CustomMessage) message.body();
System.out.println("Custom message received: "+customMessage.getSummary());
// Replying is same as publishing
CustomMessage replyMessage = new CustomMessage(200, "a00000002", "Message sent from local receiver!");
message.reply(replyMessage);
});
}
}