Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Log4j2
- class MultipleHttpServersApp {
- static void main(String[] args) {
- def vertx = Vertx.vertx()
- def port = 9003
- vertx.deployVerticle({ new HttpVerticle(port: port) }, new DeploymentOptions().setInstances(1000)) {
- log.info 'done deploying verticles, let\'s run bunch of requests'
- def client = WebClient.create(vertx, new WebClientOptions().setDefaultPort(port))
- vertx.setTimer(5_000) {
- 10_000.times {
- client.request(HttpMethod.GET, port, 'localhost', '/').send { resp ->
- if (resp.succeeded()) {
- log.info 'got resp : {}', resp.result().bodyAsString()
- } else {
- log.error 'got failed resp : {}', resp.cause()
- }
- }
- }
- }
- }
- }
- }
- @Log4j2
- class HttpVerticle extends AbstractVerticle {
- private static final AtomicInteger numInstances = new AtomicInteger(0)
- private HttpServer httpServer
- Integer port = 9003
- Integer verticleId = numInstances.incrementAndGet()
- @Override
- void start(Promise<Void> startPromise) throws Exception {
- log.info 'creating new vertx http server: verticleId={}', verticleId
- httpServer = vertx.createHttpServer()
- .requestHandler { r ->
- log.info 'got request : {}', verticleId
- r.response().end(verticleId as String)
- }
- .listen(9003) {
- log.info 'http server started : {}, {}', verticleId, it.succeeded()
- startPromise.handle(it.map(null))
- }
- }
- @Override
- void stop(Promise<Void> stopPromise) throws Exception {
- httpServer.close {
- log.info 'http server closed: {}', it.succeeded()
- stopPromise.handle(it)
- }
- }
- }
- #build.gradle:
- plugins {
- id 'groovy'
- id 'application'
- id 'com.github.johnrengelman.shadow' version '5.1.0'
- }
- ext {
- wrapperGradleVersion = gradleVersion
- }
- group = 'dburyak.sandbox.vertx'
- version = '0.0.1-SNAPSHOT'
- sourceCompatibility = 11
- targetCompatibility = 11
- mainClassName = 'dburyak.sandbox.vertx.EchoServerApp'
- repositories {
- mavenLocal()
- jcenter()
- mavenCentral()
- }
- dependencies {
- implementation "org.codehaus.groovy:groovy-all:${groovyVersion}"
- implementation "io.vertx:vertx-core:${vertxVersion}"
- implementation "io.vertx:vertx-lang-groovy:${vertxVersion}"
- implementation "io.vertx:vertx-mysql-client:${vertxVersion}"
- implementation "io.vertx:vertx-pg-client:${vertxVersion}"
- implementation "io.vertx:vertx-web-client:${vertxVersion}"
- // logging
- // log4j2 common configuration
- implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
- implementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
- // implementation "com.lmax:disruptor:${disruptorVersion}"
- implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
- implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
- // mongo
- }
- wrapper {
- gradleVersion = wrapperGradleVersion
- distributionType = 'ALL'
- }
- shadowJar {
- mergeServiceFiles {
- include 'META-INF/services/io.vertx.core.spi.VerticleFactory'
- }
- }
- run {
- systemProperties['vertx.logger-delegate-factory-class-name'] = 'io.vertx.core.logging.SLF4JLogDelegateFactory'
- }
- #gradle.properties:
- gradleVersion=6.5
- vertxVersion=3.9.1
- groovyVersion=3.0.4
- log4jVersion=2.13.0
- jacksonVersion=2.10.2
- disruptorVersion=3.4.2
- #log4j2.yml
- Configuration:
- status: info
- name: default
- appenders:
- Console:
- name: CONSOLE
- PatternLayout:
- Pattern: "%style{\
- %date{yyyy-MM-dd HH:mm:ss.SSS}\
- }{white} \
- \
- %highlight{%-5level}{FATAL=Blinking bright red, ERROR=Red, WARN=Yellow, INFO=Cyan, DEBUG=White, TRACE=Black} \
- \
- [%style{\
- %17.17thread\
- }{yellow}] \
- \
- %style{\
- %40.40logger\
- }{cyan} - \
- \
- %msg%n%throwable\
- "
- Loggers:
- Root:
- level: debug
- AppenderRef:
- ref: CONSOLE
- logger:
- - name: com.athaydes.spockframework.report
- level: warn
- - name: io.netty
- level: info
- - name: io.vertx
- level: info
- - name: io.micronaut
- level: info
- - name: org.mongodb.driver
- level: info
- - name: org.mongodb.driver.connection
- level: warn
- - name: com.hazelcast
- level: warn
- - name: com.networknt.schema
- level: warn
Add Comment
Please, Sign In to add comment