forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/3.2.0-SNAPSHOT' into 3.2.0-staging
- Loading branch information
Showing
95 changed files
with
1,698 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,393 @@ | ||
== Vert.x Ceylon examples | ||
|
||
or Ceylon Vert.x examples - as you like. | ||
|
||
=== Vert.x Stack | ||
|
||
This current stack of modules is supported: | ||
|
||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/core/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x Core] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/sql/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x SQL] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/jdbc/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x JDBC] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/web/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x Web] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/auth/common/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x Auth Common] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/auth/jwt/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x Auth JWT] | ||
- https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-lang-ceylon/ws/target/repo/io/vertx/ceylon/auth/shiro/1.0.0-SNAPSHOT/module-doc/api/index.html[Vert.x Auth Shiro] | ||
|
||
For more info please refer to http://vertx.io/docs/ | ||
|
||
=== Usage from Ceylon | ||
|
||
---- | ||
> ceylon compile examples.core.http.simple.server | ||
Note: Created module examples.core.http.simple.server/1.0.0 | ||
> ceylon run examples.core.http.simple.server/1.0.0 | ||
deployed | ||
---- | ||
|
||
The module is deployed from the Ceylon run using Vert.x API | ||
|
||
---- | ||
shared void run() { | ||
vertx.vertx().deployVerticle("ceylon:examples.core.http.simple.server/1.0.0", void (String|Throwable ar) { | ||
if (is String ar) { | ||
print("deployed"); | ||
} else { | ||
ar.printStackTrace(); | ||
} | ||
}); | ||
} | ||
---- | ||
|
||
=== Usage from Vert.x | ||
|
||
Download Vert.x 3.2 SNAPSHOT : https://vertx.ci.cloudbees.com/view/vert.x-3/job/vert.x3-stack/ws/stack-dist/target/ , add $VERTX_HOME/bin to your path | ||
|
||
Run a Ceylon Verticle from Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/http/simple/server | ||
---- | ||
|
||
Vert.x will compile first the Ceylon verticle. | ||
|
||
When the verticle is already compiled (i.e there is a `modules/examples/core/http/simple/server/1.0.0/examples.core.http.simple.server-1.0.0.car` file), it can be ran too: | ||
|
||
---- | ||
> vertx run ceylon:examples.core.http.simple.server/1.0.0 | ||
---- | ||
|
||
Some examples requires the _webroot_ folder, like the _web/staticsite_ example or the template examples, the `vertx.cwd` must be set to the parent of the _webroot`, for example: | ||
|
||
=== Core Simple Http | ||
|
||
A very simple HTTP server which always responds with the same response: | ||
|
||
link:source/examples/core/http/simple/server/Server.ceylon[Ceylon simple HTTP server] | ||
|
||
You can run the server then open a browser and point it at link:http://localhost:8080[] | ||
|
||
And a simple HTTP client which makes a request to the server. | ||
|
||
link:source/examples/core/http/simple/client/Client.ceylon[Ceylon simple HTTP client] | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/http/simple/server & | ||
> vertx run ceylon:source/examples/core/http/simple/client | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.core.http.server | ||
> ceylon compile examples.core.http.client | ||
> ceylon run examples.core.http.simple.server & | ||
> ceylon run examples.core.http.simple.client | ||
---- | ||
|
||
=== Core Http simple form upload | ||
|
||
This example demonstrates how you can handle file uploads from an HTML form submission. | ||
|
||
link:source/examples/core/http/simpleformupload/SimpleFormUploadServer.ceylon[Ceylon simple form file upload server example] | ||
|
||
You can run the server then open a browser and point it at link:http://localhost:8080[] | ||
|
||
NOTE: In practice you would probably also use Vert.x-Web for this rather than writing a server at this low level. Vert.x-Web | ||
provides built in support for HTML forms and file uploads, and avoids some of the security issues due to maliciously | ||
crafted URI paths. | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/http/simpleformupload | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.core.http.simpleformupload | ||
> ceylon run examples.core.http.simple.simpleformupload | ||
---- | ||
|
||
=== Core Websockets | ||
|
||
This example shows a Vert.x HTTP server which handles websockets connections. This example simply echoes back to the client | ||
whatever it receives on the websocket. | ||
|
||
There's also a client which connects to the server, sends some data and logs out what it receives. | ||
|
||
link:source/examples/core/http/websockets/server/Server.ceylon[Ceylon WebSockets server example] | ||
link:source/examples/core/http/websockets/client/Client.ceylon[Ceylon WebSockets client example] | ||
|
||
You can run the server then open a browser and point it at link:http://localhost:8080[] | ||
|
||
NOTE: in practice you would probably use Vert.x-Web to build a web application that uses WebSockets | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/http/websockets/server & | ||
> vertx run ceylon:source/examples/core/http/websockets/client | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.core.http.websockets.server | ||
> ceylon compile examples.core.http.websockets.client | ||
> ceylon run examples.core.http.websockets.server & | ||
> ceylon run examples.core.http.websockets.client | ||
---- | ||
|
||
=== Core exec blocking | ||
|
||
This example demonstrates how you can include blocking code in with your non blocking code in a way that doesn't | ||
block an event loop: | ||
|
||
link:source/examples/core/execblocking/ExecBlocking.ceylon[Ceylon execute blocking code example] | ||
|
||
Run the example then open a browser and point it at link:http://localhost:8080[] | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/execblocking | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.core.execblocking | ||
> ceylon run examples.core.http.execblocking | ||
---- | ||
|
||
=== Core event bus pub/sub | ||
|
||
This example demonstrates publish / subscribe messaging between a receivers and a sender. With pub/sub messaging | ||
you can have multiple subscribers who all receive messages from publishers. | ||
|
||
A receiver listens on an address on the event bus for incoming messages. When it receives a message it logs it. | ||
|
||
The sender sends a message to that address every second, when it receives a reply it logs it. | ||
|
||
link:source/examples/core/eventbus/pubsub/receiver/Receiver.ceylon[Ceylon event bus pubsub receiver] | ||
link:source/examples/core/eventbus/pubsub/sender/Sender.ceylon[Ceylon event bus pubsub sender] | ||
|
||
At the command line you should run Sender and Receiver in different consoles using the `-cluster` flag: | ||
|
||
---- | ||
> vertx run ceylon:source/examples/core/eventbus/pubsub/receiver -cluster & | ||
> vertx run ceylon:source/examples/core/eventbus/pubsub/sender -cluster | ||
---- | ||
|
||
The `-cluster` flag allows different Vert.x instances on the network to cluster the event bus together into a single | ||
event bus. | ||
|
||
=== Web Hello World | ||
|
||
The traditional hello world example. This one creates a server which just responds with "Hello World! to each request. | ||
|
||
The link:source/examples/web/helloworld/Server.ceylon[Ceylon Hello world example] | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/helloworld | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.helloworld | ||
> ceylon run examples.web.helloworld | ||
---- | ||
|
||
=== Web Rest | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/rest | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.rest | ||
> ceylon run examples.web.rest | ||
---- | ||
|
||
=== Web Simple REST Micro-service | ||
|
||
Vert.x-Web is a great fit for HTTP/REST microservices. | ||
|
||
Here's a simple micro-service example which implements an API for a product catalogue. | ||
|
||
The link:source/examples/web/rest/SimpleREST.ceylon[Ceylon REST Microservice example] | ||
|
||
The API allows you to list all products, retrieve details for a particular product and to add a new product. | ||
|
||
Product information is provided in JSON. | ||
|
||
List all products:: GET /products | ||
Get a product:: GET /products/<product_id> | ||
Add a product:: PUT /products/<product_id> | ||
|
||
Run the server then open your browser and hit | ||
link:http://localhost:8080/products[list products] to start playing with the API. | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/rest | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.rest | ||
> ceylon run examples.web.rest | ||
---- | ||
|
||
=== Web Static web server example | ||
|
||
This example shows a very simple web server which serves static files from disk. | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/staticsite -Dvertx.cwd=source/examples/web/staticsite | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.staticsite | ||
> ceylon run examples.web.staticsite | ||
---- | ||
|
||
=== Web Form | ||
|
||
This example shows a basic HTML form web-site and a backend end point that just returns an customizable hello world | ||
message. | ||
|
||
The link:source/examples/web/form/Server.ceylon[Ceylon form example] | ||
|
||
Run, then open your browser and hit | ||
link:http://localhost:8080 and click around the links | ||
|
||
- Vert.x | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/form | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.form | ||
> ceylon run examples.web.form | ||
---- | ||
|
||
=== Web JDBC example | ||
|
||
This example shows a basic REST server backed by a JDBC client. It is exactly the same as the REST client however its | ||
data is persisted in a relational database using the asynchronous JDBC client. | ||
|
||
The link:source/examples/web/jdbc/Server.ceylon[Ceylon jdbc example] | ||
|
||
Run, then open your browser and hit | ||
link:http://localhost:8080/products to get the list of products, or link:http://localhost:8080/products/0 for accessing | ||
a product with id 0. In order to create new products use the POST method to link:http://localhost:8080/products | ||
|
||
- Vert.x : Copy the HSQLDB driver in $VERTX_HOME/lib (the C3P0 connection pool needs it), then run it | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/jdbc | ||
---- | ||
|
||
- Ceylon: Need the option --flat-classpath | ||
|
||
---- | ||
> ceylon compile examples.web.jdbc | ||
> ceylon run --flat-classpath examples.web.jdbc | ||
---- | ||
|
||
=== Web static site with templating | ||
|
||
This example shows a simple web-site containing some static pages and also a page dynamically generated using templates. | ||
|
||
The link:source/examples/web/templating[templating example] | ||
|
||
The dynamic page outputs some information (path and headers) of the request. It uses the MVEL template engine but you | ||
could use any of the other template engines if you prefer. | ||
|
||
Run, then open your browser and hit | ||
link:http://localhost:8080 and click on the links | ||
|
||
==== Web templating with Jade | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/templating/jade -Dvertx.cwd=source/examples/web/templating/jade | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.templating.jade | ||
> ceylon run --flat-classpath examples.web.templating.jade | ||
---- | ||
|
||
==== Web templating with Handlebars | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/templating/handlebars -Dvertx.cwd=source/examples/web/templating/handlebars | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.templating.handlebars | ||
> ceylon run --flat-classpath examples.web.templating.handlebars | ||
---- | ||
|
||
==== Web templating with MVEL | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/templating/mvel -Dvertx.cwd=source/examples/web/templating/mvel | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.templating.mvel | ||
> ceylon run --flat-classpath examples.web.templating.mvel | ||
---- | ||
|
||
==== Web templating with Thymeleaf | ||
|
||
---- | ||
> vertx run ceylon:source/examples/web/templating/thymeleaf -Dvertx.cwd=source/examples/web/templating/thymeleaf | ||
---- | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.web.templating.thymeleaf | ||
> ceylon run --flat-classpath examples.web.templating.thymeleaf | ||
---- | ||
|
||
=== Embeded Http | ||
|
||
Simple http server example without verticles, Ceylon only. | ||
|
||
- Ceylon | ||
|
||
---- | ||
> ceylon compile examples.embed.http | ||
> ceylon run examples.embed.http | ||
---- |
Oops, something went wrong.