Created by Daniel Jahre
var vertx = require('vertx');
vertx.createHttpServer().requestHandler(function(req) {
req.response.end("Hello World!");
}).listen(8080, 'localhost');
vertx run server.js
package linuxwochen
def eb = vertx.eventBus
def timerId = vertx.setPeriodic(1000) {
timerId ->
eb.publish("datetimeupdate", new Date().toString())
}
package linuxwochen
def server = vertx.createHttpServer()
def config = ["prefix": "/eventbus"]
def eb = vertx.eventBus
container.deployVerticle("DateSender.groovy")
eb.registerHandler("datetimeupdate", {
message -> println("${message.body}")
} )
eb.registerHandler("browser", {
message -> println("browser connected:" +
new Date().toString() +
": ${message.body}")
})
server.requestHandler { req ->
def file = req.path == "/" ? "sockjsclient.html" : req.path
//attention, might be escaped ..
req.response.sendFile("./" + file)
}
vertx.createSockJSServer(server).bridge(config, [[:]], [[:]])
server.listen(8080)
def server = vertx.createHttpServer()
def config = ["prefix": "/eventbus"]
// This defines the matches for client --> server traffic
def inboundPermitted = []
// Let through any messages sent to 'demo.orderMgr'
inboundPermitted << ["address": "demo.orderMgr"]
// Allow messages to the address 'demo.persistor' as long as the messages
// have an action field with value 'find' and a collection field with value
// 'albums'
inboundPermitted << ["address": "demo.persistor",
"match": [ "action": "find",
"collection": "albums"]]
// Allow through any message with a field `wibble` with value `foo`.
inboundPermitted << ["match", ["wibble": "foo"]]
// This defines the matches for server --> client traffic
def outboundPermitted = []
// Let through any messages from address "ticker.mystock"
outboundPermitted << ["address": "ticker.mystock"]
// Let through any messages from addresses starting with "news." (e.g. news.europe, news.usa, etc)
outboundPermitted << ["address_re": "news\\..+"]
vertx.createSockJSBridge(server).bridge(config, inboundPermitted, outboundPermitted)
server.listen(8080)
Vert.x Example