diff --git a/jasync-examples/README.adoc b/jasync-examples/README.adoc new file mode 100644 index 000000000..4b2f25e31 --- /dev/null +++ b/jasync-examples/README.adoc @@ -0,0 +1,34 @@ += Vert.x Simplest vertx-mysql-postgresql-client project + +This project shows a very simple hello world Vert.x project using vertx-mysql-postgresql-client, which has a simple HTTP server which +returns the result of 'SELECT 0' on mysql db. + +Under the hood vertx-mysql-postgresql-client uses jasync-sql as the database driver. + +In this example Vert.x is used embedded. I.e. we use the Vert.x APIs directly in our own classes rather than deploying +the code in verticles. + +You can run or debug the example in your IDE by just right clicking the main class and run as.. or debug as... + +The pom.xml uses the Maven shade plugin to assemble the application and all it's dependencies into a single "fat" jar. + +To run with maven + + mvn compile exec:java + +To build a "fat jar" + + mvn package + +To run the fat jar: + + java -jar target/jasync-examples-3.6.3-fat.jar + +(You can take that jar and run it anywhere there is a Java 8+ JDK. It contains all the dependencies it needs so you +don't need to install Vert.x on the target machine). + +You can also run the fat jar with maven: + + mvn package exec:exec@run-app + +Now point your browser at http://localhost:8080 diff --git a/jasync-examples/pom.xml b/jasync-examples/pom.xml new file mode 100644 index 000000000..3711ac477 --- /dev/null +++ b/jasync-examples/pom.xml @@ -0,0 +1,131 @@ + + + + 4.0.0 + + io.vertx + jasync-examples + 3.6.3 + + + + io.vertx.example.HelloWorldEmbedded + + + + + io.vertx + vertx-core + ${project.version} + + + io.vertx + vertx-mysql-postgresql-client-jasync + ${project.version} + + + org.slf4j + slf4j-api + 1.7.25 + + + org.slf4j + slf4j-simple + 1.7.25 + + + + + + + + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + + + + ${exec.mainClass} + + + + META-INF/services/io.vertx.core.spi.VerticleFactory + + + + + ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.4.0 + + + + run-app + + exec + + + java + + -jar + target/${project.artifactId}-${project.version}-fat.jar + + + + + + + + + + + staging + + + staging + https://oss.sonatype.org/content/repositories/iovertx-3814/ + + + + + + diff --git a/jasync-examples/src/main/java/io/vertx/example/HelloWorldEmbedded.java b/jasync-examples/src/main/java/io/vertx/example/HelloWorldEmbedded.java new file mode 100644 index 000000000..460b05c5a --- /dev/null +++ b/jasync-examples/src/main/java/io/vertx/example/HelloWorldEmbedded.java @@ -0,0 +1,45 @@ +package io.vertx.example; + +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.asyncsql.MySQLClient; +import io.vertx.ext.sql.SQLClient; +import io.vertx.ext.sql.SQLConnection; + + +/** + * @author oshai + */ +public class HelloWorldEmbedded { + + public static void main(String[] args) { + JsonObject mySQLClientConfig = new JsonObject() + .put("username", "mysql_async") + .put("password", "root") + .put("database", "mysql_async_tests") + .put("port", 33018) + .put("host", "localhost"); + SQLClient mySQLClient = MySQLClient.createShared(Vertx.vertx(), mySQLClientConfig); + + // Create an HTTP server which simply returns "Hello World!" to each request. + Vertx.vertx().createHttpServer() + .requestHandler(req -> { + mySQLClient.getConnection(res -> { + if (res.succeeded()) { + + SQLConnection connection = res.result(); + + // Got a connection + connection.query("SELECT 0", result -> + req.response().end("Got response " + result.result().getNumRows())); + } else { + // Failed to get connection - deal with it + req.response().end("Failed!"); + } + }); + + }) + .listen(8080); + } + +}