-
Notifications
You must be signed in to change notification settings - Fork 2
/
Server.java
39 lines (30 loc) · 1.39 KB
/
Server.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
31
32
33
34
35
36
37
38
39
import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import io.vertx.ext.web.handler.sockjs.BridgeOptions;
import io.vertx.ext.web.handler.sockjs.PermittedOptions;
import io.vertx.ext.web.handler.sockjs.SockJSHandler;
import io.vertx.ext.web.handler.sockjs.BridgeEventType;
public class Server extends AbstractVerticle {
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
String busAddress = "paintAddressX";
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress(busAddress));
options.addInboundPermitted(new PermittedOptions().setAddress(busAddress));
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
System.out.println("A socket was created");
}
event.complete(true);
}));
// static assets in local folder "webroot"
// and available at http://localhost:8080/
router.route().handler(StaticHandler.create());
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
System.out.println("Everyting is non-blocking Async :-)");
vertx.setPeriodic(1000, t -> vertx.eventBus().publish("paintAddress", "Server Now " + new java.util.Date()));
} // start
}