Created
July 21, 2014 13:09
-
-
Save paulosuzart/cd0562573105b6661c3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.vertx.groovy.core.http.RouteMatcher | |
import java.util.concurrent.atomic.AtomicLong | |
def counterMap = vertx.getSharedData().getMap("demo.mymap") | |
counterMap.put('bvs', 0) | |
def verticleId = new Random().nextInt(10 ** 20) | |
def logger = container.logger | |
logger.info "Verticle ID: $verticleId" | |
def server = vertx.createHttpServer() | |
def router = new RouteMatcher() | |
router.noMatch { | |
it.response.with { | |
statusMessage = 404 | |
} | |
} | |
router.getWithRegEx("/(\\d*)") { req -> | |
def timestamp = req.params['param0'] | |
def referer = req.headers['Referer'] ?: "UNKNOWN" | |
def addr = req.getRemoteAddress() | |
logger.info "[$verticleId] Logging request from $referer, with timestamp: $timestamp and IP: $addr" | |
counterMap.bvs += 1 | |
req.response.with { | |
statusCode = 200 | |
statusMessage = "Tracked" | |
end "Tracked $timestamp. Total so far $counterMap.bvs" | |
} | |
} | |
def conf = container.getConfig() | |
def eb = vertx.eventBus | |
//eb.registerHandler("counter.start") { msg -> | |
server.requestHandler(router.asClosure()).listen(conf.server.port, conf.server.host) | |
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"server" : { | |
"host" : "192.168.1.50", | |
"port" : 8080} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment