File tree 6 files changed +101
-0
lines changed
src/main/groovy/verticles
6 files changed +101
-0
lines changed Original file line number Diff line number Diff line change @@ -362,4 +362,24 @@ export NODE_PATH=$PWD
362
362
vertx run my_npm_verticle.js
363
363
----
364
364
365
+ == Groovy verticles
366
+
367
+ Vert.x supports several _formats_ to develop verticles in Groovy. This link:src/main/groovy/verticles[directory]
368
+ illustrates the different formats:
369
+
370
+ * link:src/main/groovy/verticles/script.groovy[plain script] - a verticle developed as a plain Groovy script
371
+ * link:src/main/groovy/verticles/script-with-hooks.groovy[plain script with hooks] - a verticle developed as a script
372
+ with hooks called by vert.x when the verticle is deployed and un-deployed
373
+ * link:src/main/groovy/verticles/verticle-extending-abstract-verticle.groovy[class extending AbstractVerticle] - a
374
+ verticle developed as a class extending `AbstractVerticle`
375
+ * link:src/main/groovy/verticles/verticle-extending-groovy-verticle.groovy[class extending GroovyVerticle] - a
376
+ verticle developed as a class extending `GroovyVerticle`
377
+
378
+ You can run these examples using the `vertx` command line. For example:
379
+
380
+ ```
381
+ vertx run script.groovy
382
+ ```
383
+
384
+
365
385
Original file line number Diff line number Diff line change
1
+ This directory contains examples of the different _ formats_ supported to develop Groovy verticles.
2
+ ** Do not remove** , the files are not generated.
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A verticle developed as a groovy script with hooks. vert.x calls the `vertxStart` and `vertxStop` method when the verticle
3
+ * is deployed and un-deployed.
4
+ * @author <a href =" http://escoffier.me" >Clement Escoffier</a>
5
+ */
6
+
7
+ void vertxStart () {
8
+ println " starting"
9
+ vertx. createHttpServer(). requestHandler({ request ->
10
+ request. response(). end(" Hello world" )
11
+ }). listen(8080 )
12
+
13
+ }
14
+
15
+ void vertxStop () {
16
+ println " stopping"
17
+ }
18
+
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A verticle developed as a plain groovy script. The code is executed in the Vert.x Event Loop
3
+ * @author <a href =" http://escoffier.me" >Clement Escoffier</a>
4
+ */
5
+
6
+
7
+ println " Starting from " + Thread . currentThread(). name
8
+
9
+ vertx. createHttpServer(). requestHandler({ request ->
10
+ request. response(). end(" Hello world" )
11
+ }). listen(8080 )
Original file line number Diff line number Diff line change
1
+ import io.vertx.core.AbstractVerticle
2
+
3
+ /**
4
+ * A verticle developed as class extending `AbstractVerticle`.
5
+ * @author <a href =" http://escoffier.me" >Clement Escoffier</a>
6
+ */
7
+
8
+ class MyVerticle extends AbstractVerticle {
9
+
10
+ @Override
11
+ void start () throws Exception {
12
+ println " starting"
13
+
14
+ vertx. createHttpServer(). requestHandler({ request ->
15
+ request. response(). end(" Hello world" )
16
+ }). listen(8080 )
17
+ }
18
+
19
+ @Override
20
+ void stop () throws Exception {
21
+ println " stopping"
22
+ }
23
+ }
24
+
25
+
Original file line number Diff line number Diff line change
1
+ import io.vertx.lang.groovy.GroovyVerticle
2
+
3
+ /**
4
+ * A verticle developed as class extending `GroovyVerticle`.
5
+ * @author <a href =" http://escoffier.me" >Clement Escoffier</a>
6
+ */
7
+
8
+ class MyVerticle extends GroovyVerticle {
9
+
10
+ @Override
11
+ void start () throws Exception {
12
+ println " starting"
13
+
14
+ vertx. createHttpServer(). requestHandler({ request ->
15
+ request. response(). end(" Hello world" )
16
+ }). listen(8080 )
17
+ }
18
+
19
+ @Override
20
+ void stop () throws Exception {
21
+ println " stopping"
22
+ }
23
+ }
24
+
25
+
You can’t perform that action at this time.
0 commit comments