forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.groovy
41 lines (32 loc) · 1.08 KB
/
dashboard.groovy
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
40
41
import io.vertx.groovy.ext.dropwizard.MetricsService
import io.vertx.groovy.ext.web.Router
import io.vertx.groovy.ext.web.handler.sockjs.SockJSHandler
import io.vertx.groovy.ext.web.handler.StaticHandler
def service = MetricsService.create(vertx)
def router = Router.router(vertx)
// Allow outbound traffic to the news-feed address
def options = [
outboundPermitteds:[
[
address:"metrics"
]
]
]
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options))
// Serve the static resources
router.route().handler(StaticHandler.create())
def httpServer = vertx.createHttpServer()
httpServer.requestHandler(router.&accept).listen(8080)
// Send a metrics events every second
vertx.setPeriodic(1000, { t ->
def metrics = service.getMetricsSnapshot(vertx.eventBus())
vertx.eventBus().publish("metrics", metrics)
})
// Send some messages
def random = new java.util.Random()
vertx.eventBus().consumer("whatever", { msg ->
vertx.setTimer(10 + random.nextInt(50), { id ->
vertx.eventBus().send("whatever", "hello")
})
})
vertx.eventBus().send("whatever", "hello")