From bed82f46032dad1ca4984ef6a20b5bafe9cee048 Mon Sep 17 00:00:00 2001 From: hm Date: Fri, 17 Nov 2017 18:51:25 +0800 Subject: [PATCH] aaa --- .classpath | 36 ++++++++++++++++++++++++++++++++++++ .project | 23 +++++++++++++++++++++++ .settings/org.eclipse.core.resources.prefs | 2 ++ .settings/org.eclipse.jdt.core.prefs | 5 +++++ .settings/org.eclipse.m2e.core.prefs | 4 ++++ .vertx/file-cache-14b8b910-d49e-45b1-aac7-1c3253158c39/my/index.html | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config/dbconfig.json | 3 +++ pom.xml | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.txt | 28 ++++++++++++++++++++++++++++ src/main/java/com/xxxcom/model/Users.java | 35 +++++++++++++++++++++++++++++++++++ src/main/java/com/xxxcom/model/vo/Msg_Vo.java | 35 +++++++++++++++++++++++++++++++++++ src/main/java/com/xxxcom/util/FileUtil.java | 31 +++++++++++++++++++++++++++++++ src/main/java/com/xxxcom/util/JDBCUtil.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/xxxcom/xxxproduct/JDBCExample.java | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/xxxcom/xxxproduct/Main.java | 19 +++++++++++++++++++ src/main/java/com/xxxcom/xxxproduct/MyFirstVerticle.java | 23 +++++++++++++++++++++++ src/main/java/com/xxxcom/xxxproduct/XXXSrv.java | 298 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/resources/default-ignite.xml | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/resources/my/index.html | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/resources/vertx-default-jul-logging.properties | 30 ++++++++++++++++++++++++++++++ target/classes/com/xxxcom/model/Users.class | Bin 0 -> 1085 bytes target/classes/com/xxxcom/model/vo/Msg_Vo.class | Bin 0 -> 924 bytes target/classes/com/xxxcom/util/FileUtil.class | Bin 0 -> 2251 bytes target/classes/com/xxxcom/util/JDBCUtil.class | Bin 0 -> 6801 bytes target/classes/com/xxxcom/xxxproduct/JDBCExample.class | Bin 0 -> 4256 bytes target/classes/com/xxxcom/xxxproduct/Main.class | Bin 0 -> 695 bytes target/classes/com/xxxcom/xxxproduct/MyFirstVerticle.class | Bin 0 -> 1992 bytes target/classes/com/xxxcom/xxxproduct/XXXSrv.class | Bin 0 -> 13904 bytes target/classes/default-ignite.xml | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ target/classes/my/index.html | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ target/classes/vertx-default-jul-logging.properties | 30 ++++++++++++++++++++++++++++++ target/maven-archiver/pom.properties | 5 +++++ target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst | 8 ++++++++ target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst | 8 ++++++++ target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst | 0 target/xxx-srv-1.0.0-SNAPSHOT-fat.jar | Bin 0 -> 28303333 bytes target/xxx-srv-1.0.0-SNAPSHOT.jar | Bin 0 -> 21644 bytes 37 files changed, 1686 insertions(+), 0 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .vertx/file-cache-14b8b910-d49e-45b1-aac7-1c3253158c39/my/index.html create mode 100644 config/dbconfig.json create mode 100644 pom.xml create mode 100644 readme.txt create mode 100644 src/main/java/com/xxxcom/model/Users.java create mode 100644 src/main/java/com/xxxcom/model/vo/Msg_Vo.java create mode 100644 src/main/java/com/xxxcom/util/FileUtil.java create mode 100644 src/main/java/com/xxxcom/util/JDBCUtil.java create mode 100644 src/main/java/com/xxxcom/xxxproduct/JDBCExample.java create mode 100644 src/main/java/com/xxxcom/xxxproduct/Main.java create mode 100644 src/main/java/com/xxxcom/xxxproduct/MyFirstVerticle.java create mode 100644 src/main/java/com/xxxcom/xxxproduct/XXXSrv.java create mode 100644 src/main/resources/default-ignite.xml create mode 100644 src/main/resources/my/index.html create mode 100644 src/main/resources/vertx-default-jul-logging.properties create mode 100644 target/classes/com/xxxcom/model/Users.class create mode 100644 target/classes/com/xxxcom/model/vo/Msg_Vo.class create mode 100644 target/classes/com/xxxcom/util/FileUtil.class create mode 100644 target/classes/com/xxxcom/util/JDBCUtil.class create mode 100644 target/classes/com/xxxcom/xxxproduct/JDBCExample.class create mode 100644 target/classes/com/xxxcom/xxxproduct/Main.class create mode 100644 target/classes/com/xxxcom/xxxproduct/MyFirstVerticle.class create mode 100644 target/classes/com/xxxcom/xxxproduct/XXXSrv.class create mode 100644 target/classes/default-ignite.xml create mode 100644 target/classes/my/index.html create mode 100644 target/classes/vertx-default-jul-logging.properties create mode 100644 target/maven-archiver/pom.properties create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 target/xxx-srv-1.0.0-SNAPSHOT-fat.jar create mode 100644 target/xxx-srv-1.0.0-SNAPSHOT.jar diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fae1a2b --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..0063b9b --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + vertx-demo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..6532c37 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/resources/my/index.html=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..714351a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.vertx/file-cache-14b8b910-d49e-45b1-aac7-1c3253158c39/my/index.html b/.vertx/file-cache-14b8b910-d49e-45b1-aac7-1c3253158c39/my/index.html new file mode 100644 index 0000000..339479f --- /dev/null +++ b/.vertx/file-cache-14b8b910-d49e-45b1-aac7-1c3253158c39/my/index.html @@ -0,0 +1,144 @@ + + + + + test + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/config/dbconfig.json b/config/dbconfig.json new file mode 100644 index 0000000..0a7e720 --- /dev/null +++ b/config/dbconfig.json @@ -0,0 +1,3 @@ +{ + "test" : "1111" +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..257b683 --- /dev/null +++ b/pom.xml @@ -0,0 +1,193 @@ + + 4.0.0 + com.xxxcom.xxxproduct + xxx-srv + 1.0.0-SNAPSHOT + + + + com.xxxcom.xxxproduct.XXXSrv + 3.4.2 + + + + + + + io.vertx + vertx-core + ${vertx.version} + + + + io.vertx + vertx-hazelcast + ${vertx.version} + + + + io.vertx + vertx-web + ${vertx.version} + + + io.vertx + vertx-redis-client + ${vertx.version} + + + + io.vertx + vertx-mysql-postgresql-client + 3.5.0 + + + + org.apache.commons + commons-lang3 + 3.4 + + + org.apache.logging.log4j + log4j-api + 2.8 + + + org.slf4j + slf4j-api + 1.7.23 + + + + + io.vertx + vertx-jdbc-client + 3.1.0 + + + postgresql + postgresql + 9.1-901.jdbc4 + + + + + io.vertx + vertx-mongo-service + 3.3.0 + + + io.vertx + vertx-config + 3.4.0 + + + com.google.code.gson + gson + 2.8.2 + + + + + + + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + + + + io.vertx.core.Launcher + ${main.verticle} + + + + 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 + + java + + + io.vertx.core.Launcher + + run + ${main.verticle} + + + + + + run-app + + exec + + + java + + -jar + target/${project.artifactId}-${project.version}-fat.jar + + + + + + + + + + + staging + + + staging + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..b862610 --- /dev/null +++ b/readme.txt @@ -0,0 +1,28 @@ +微服务开发流程 +1. 开发环境准备 + JDK 1.8+ + maven 3.3+ + +2. 新建微服务 + 微服务类继承AbstractVerticle基础类,实现load、unload(可选)方法、在load方法中注册各种服务。 + 通过vertx.eventBus方法获取消息总线实例,实现消息监听或消息发送。 + 示例代码: + +3. 程序打包 + 设置pom.xml /project/properties/路径下main.verticle的值为微服务实现类,如: + com.xxxcom.xxxproduct.XXXSrv + + 执行mvn clean package 进行打包 + +4. 程序运行 + java -jar <你的微服务jar包> + 集群模式 java -jar <你的微服务jar包> -cluster + 集群多实例模式 java -jar <你的微服务jar包> -cluster -instance 4 + 注意:应运行肥包 + +5. 注意事项 + 如需要执行阻塞IO的相关操作,如BIO网络请求、文件读取等,需包含在vertx.executeBlocking里 + 不提倡自行创建新线程 +基于JVM、轻量级、高性能的应用平台 + + \ No newline at end of file diff --git a/src/main/java/com/xxxcom/model/Users.java b/src/main/java/com/xxxcom/model/Users.java new file mode 100644 index 0000000..efb920d --- /dev/null +++ b/src/main/java/com/xxxcom/model/Users.java @@ -0,0 +1,35 @@ +package com.xxxcom.model; + +import java.util.concurrent.atomic.AtomicInteger; + +public class Users { + + private static final AtomicInteger COUNTER = new AtomicInteger(1); + + + private final Integer id; + + public Integer getId() { + return id; + } + + public Users() { + this.id = COUNTER.getAndIncrement(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + private String name; + + public Users(String name) { + this.id = COUNTER.getAndIncrement(); + this.name = name; + } + +} diff --git a/src/main/java/com/xxxcom/model/vo/Msg_Vo.java b/src/main/java/com/xxxcom/model/vo/Msg_Vo.java new file mode 100644 index 0000000..6e4851a --- /dev/null +++ b/src/main/java/com/xxxcom/model/vo/Msg_Vo.java @@ -0,0 +1,35 @@ +package com.xxxcom.model.vo; + +import io.vertx.core.json.JsonObject; + +public class Msg_Vo { + + private int code; + private String msg; + private Object data; + private int total; + + public Msg_Vo(int code, Object data) { + this.code = code; + this.data = data; + } + + public Msg_Vo(int code, String msg) { + + this.code = code; + this.msg = msg; + } + + public Msg_Vo(int code, Object data, String msg) { + this(code, data); + this.data = data; + this.msg = msg; + } + + public Msg_Vo(int code, Object data, int total) { + this(code, data); + this.total = total; + } + + +} diff --git a/src/main/java/com/xxxcom/util/FileUtil.java b/src/main/java/com/xxxcom/util/FileUtil.java new file mode 100644 index 0000000..0de727f --- /dev/null +++ b/src/main/java/com/xxxcom/util/FileUtil.java @@ -0,0 +1,31 @@ +package com.xxxcom.util; + +import io.vertx.core.Vertx; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.file.FileSystem; +import io.vertx.core.json.JsonObject; + +public class FileUtil { + + private static String content=""; + + + + //读取文件 + public String readFile(Vertx vertx,String filepath) { + + FileSystem system=vertx.fileSystem().readFile(filepath, result -> { + if (result.succeeded()) { + System.out.println("aaa:"+result.result().toString()); + + } else { + System.err.println("Oh oh ..." + result.cause()); + + } + }); + System.out.println("content:"+content); + + return content; + } + +} diff --git a/src/main/java/com/xxxcom/util/JDBCUtil.java b/src/main/java/com/xxxcom/util/JDBCUtil.java new file mode 100644 index 0000000..c2a6a30 --- /dev/null +++ b/src/main/java/com/xxxcom/util/JDBCUtil.java @@ -0,0 +1,98 @@ +package com.xxxcom.util; + +import com.xxxcom.model.vo.Msg_Vo; + +import io.vertx.config.ConfigRetriever; +import io.vertx.config.ConfigRetrieverOptions; +import io.vertx.config.ConfigStoreOptions; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.asyncsql.AsyncSQLClient; +import io.vertx.ext.asyncsql.PostgreSQLClient; +import io.vertx.ext.sql.SQLConnection; + +public class JDBCUtil { + + + private static AsyncSQLClient client; + + // 获取连接字符串 + private Future getSqlStr() { + Vertx vertx = Vertx.vertx(); + Future future = Future.future(); + ConfigStoreOptions fileStore = new ConfigStoreOptions().setType("file") + .setConfig(new JsonObject().put("path", "config/dbconfig.json")); + ConfigRetrieverOptions options = new ConfigRetrieverOptions().addStore(fileStore); + ConfigRetriever retriever = ConfigRetriever.create(vertx, options); + retriever.getConfig(ar -> { + if (ar.failed()) { + // Failed to retrieve the configuration + } else { + JsonObject config = ar.result(); + future.complete(config); + } + }); + return future; + } + + public AsyncSQLClient getClient(Vertx vertx) { + + if (client == null) { + // 获取配置文件连接信息 + client = PostgreSQLClient.createShared(vertx, + new JsonObject().put("host", "120.76.158.63").put("port", 5432).put("database", "iot") + .put("maxPoolSize", 10).put("username", "postgres").put("charset", "UTF-8") + .put("password", "Nmamtf_098")); + + } + System.out.println("client:" + client); + return client; + + } + + /** + * 获取数据库连接 + * + * @param vertx + * @return + */ + public Future getConnection(Vertx vertx) { + Future future = Future.future(); + AsyncSQLClient client = getClient(vertx); + client.getConnection(conn -> { + if (conn.succeeded()) { + SQLConnection connresult = conn.result(); + System.out.println("connresult:" + connresult); + future.complete(connresult); + + } else { + future.fail(conn.cause()); + } + }); + + System.out.println("future:" + future); + + return future; + } + + // 查询 + public Future query(Vertx vertx,String sql,JsonArray params){ + Future future = Future.future(); + getConnection(vertx).setHandler(result->{ + SQLConnection conn=result.result(); + conn.queryWithParams(sql, params, query->{ + if (query.succeeded()) { + JsonArray arr = new JsonArray(); + query.result().getRows().forEach(arr::add); + future.complete(new Msg_Vo(0, arr.encode())); + } else { + future.fail(query.cause()); + } + }); + }); + return future; + } + +} diff --git a/src/main/java/com/xxxcom/xxxproduct/JDBCExample.java b/src/main/java/com/xxxcom/xxxproduct/JDBCExample.java new file mode 100644 index 0000000..68c8538 --- /dev/null +++ b/src/main/java/com/xxxcom/xxxproduct/JDBCExample.java @@ -0,0 +1,68 @@ +package com.xxxcom.xxxproduct; + + +import com.mongodb.MongoCommandException; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.asyncsql.AsyncSQLClient; +import io.vertx.ext.asyncsql.PostgreSQLClient; +import io.vertx.ext.jdbc.JDBCClient; +import io.vertx.ext.sql.SQLConnection; + +public class JDBCExample extends AbstractVerticle { + + + public JDBCExample(){ + vertx=Vertx.vertx(); + + } + + @Override + public void start() throws Exception { + + final AsyncSQLClient client = PostgreSQLClient.createShared(vertx, new JsonObject() + .put("url", "jdbc:postgresql://120.76.158.62:5432/iot") + .put("driver_class", "org.postgresql.Driver") + .put("max_pool_size",10) + .put("username", "postgres") + .put("password", "Nmamtf_com")); + + client.getConnection(conn -> { + if (conn.failed()) { + System.err.println(conn.cause().getMessage()); + return; + } + + final SQLConnection connection = conn.result(); + connection.execute("create table test(id int primary key, name varchar(255))", res -> { + if (res.failed()) { + throw new RuntimeException(res.cause()); + } + // insert some test data + connection.execute("insert into test values(1, 'Hello')", insert -> { + // query some data + connection.query("select * from test", rs -> { + for (JsonArray line : rs.result().getResults()) { + System.out.println(line.encode()); + } + + // and close the connection + connection.close(done -> { + if (done.failed()) { + throw new RuntimeException(done.cause()); + } + }); + }); + }); + }); + }); + } + + + public static void main(String[] args) { + + } +} diff --git a/src/main/java/com/xxxcom/xxxproduct/Main.java b/src/main/java/com/xxxcom/xxxproduct/Main.java new file mode 100644 index 0000000..fd54520 --- /dev/null +++ b/src/main/java/com/xxxcom/xxxproduct/Main.java @@ -0,0 +1,19 @@ +package com.xxxcom.xxxproduct; + +import io.vertx.core.Future; +import io.vertx.core.Vertx; + +public class Main { + + public static void main(String[] args) { + + XXXSrv jdbc=new XXXSrv(); + try { + jdbc.start(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/xxxcom/xxxproduct/MyFirstVerticle.java b/src/main/java/com/xxxcom/xxxproduct/MyFirstVerticle.java new file mode 100644 index 0000000..4352baa --- /dev/null +++ b/src/main/java/com/xxxcom/xxxproduct/MyFirstVerticle.java @@ -0,0 +1,23 @@ +package com.xxxcom.xxxproduct; + + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.http.HttpServerResponse; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.jdbc.JDBCClient; +import io.vertx.ext.web.Router; + +public class MyFirstVerticle extends AbstractVerticle { + + @Override + public void start() throws Exception { + Router router = Router.router(vertx); + + // Bind "/" to our hello message - so we are still compatible. + router.route("/").handler(routingContext -> { + HttpServerResponse response = routingContext.response(); + response.putHeader("content-type", "text/html;charset=UTF-8") + .end("

Hello from my first Vert.x 3 application

"); + }); + } +} diff --git a/src/main/java/com/xxxcom/xxxproduct/XXXSrv.java b/src/main/java/com/xxxcom/xxxproduct/XXXSrv.java new file mode 100644 index 0000000..adaee5c --- /dev/null +++ b/src/main/java/com/xxxcom/xxxproduct/XXXSrv.java @@ -0,0 +1,298 @@ +package com.xxxcom.xxxproduct; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.xxxcom.model.vo.Msg_Vo; +import com.xxxcom.util.JDBCUtil; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpServerResponse; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.sql.SQLConnection; +import io.vertx.ext.web.Router; +import io.vertx.ext.web.RoutingContext; +import io.vertx.ext.web.handler.BodyHandler; +import io.vertx.ext.web.handler.StaticHandler; + +public class XXXSrv extends AbstractVerticle { + + public XXXSrv() { + vertx = Vertx.vertx(); + + } + JDBCUtil jdbc =new JDBCUtil(); + + @Override + public void start() throws Exception { + /* + * EventBus eb = vertx.eventBus(); eb.consumer("abc", // 这个是微服务监听地址(功能号) + * r -> { // 处理函数 try { + * + * JsonObject request = (JsonObject) r.body(); // 微服务之间通信采用JSON String + * param1 = request.getString("param1"); // 这里获取参数 String param2 = + * request.getString("param2"); + * + * r.reply(makeReply(0, "", "world")); } catch (Exception e) { + * r.reply(makeReply(-1, "未知错误", null)); } + * + * }); + */ + /* + * System.out.println("begin"); final JDBCClient client = + * JDBCClient.createShared(vertx, new JsonObject().put("url", + * "jdbc:postgresql://120.76.158.63:5432/iot") .put("driver_class", + * "org.postgresql.Driver") .put("max_pool_size", 10).put("username", + * "postgres") .put("password", "Nmamtf_098")); + * + * client.getConnection(conn -> { if (conn.failed()) { + * System.out.println("1111"); + * System.err.println(conn.cause().getMessage()); return; } + * System.out.println(12223); final SQLConnection connection = + * conn.result(); connection.execute( + * "create table test(id int primary key, name varchar(255))", res -> { + * if (res.failed()) { throw new RuntimeException(res.cause()); } // + * insert some test data connection.execute( + * "insert into test values(1, 'Hello')", insert -> { // query some data + * connection.query("select * from test", rs -> { for (JsonArray line : + * rs.result().getResults()) { System.out.println(line.encode()); } + * + * // and close the connection connection.close(done -> { if + * (done.failed()) { throw new RuntimeException(done.cause()); } }); }); + * }); }); }); + */ + } + + @Override + public void stop() throws Exception { + + } + + private JsonObject makeReply(int code, String msg, Object data) { + if (data == null) { + data = new JsonObject(); + } + return new JsonObject().put("result", new JsonObject().put("code", code).put("msg", msg)).put("data", data); + } + + public static void main(String[] args) { + // Create an HTTP server which simply returns "Hello World!" to each + // request. + Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(9090); + } + + @Override + public void start(Future fut) { + + Router router = Router.router(vertx); + + // 页面访问地址 + router.route("/my/*").handler(StaticHandler.create("my")); + + vertx.createHttpServer().requestHandler(router::accept).listen( + // Retrieve the port from the configuration + config().getInteger("http.port", 8080), result -> { + if (result.succeeded()) { + fut.complete(); + } else { + fut.fail(result.cause()); + } + }); + + + // 获取列表 + //router.get("/api/getUsers").handler(this::getAll); + + router.route("/api/user*").handler(BodyHandler.create());// 设置全局请求 + // 获取列表 + router.get("/api/user/list").handler(this::getAll); + // 添加 + router.post("/api/user").handler(this::adduser); + // 修改 + router.put("/api/user").handler(this::updateuser); + // 删除 + router.delete("/api/user/:id").handler(this::deleteuser); + } + + // 查询 + private void getAll(RoutingContext routingContext) { + System.out.println("load in"); + + HttpServerResponse response = routingContext.response(); + //JDBCUtil jdbc = new JDBCUtil(); + /* jdbc.getConnection(vertx).setHandler(conn->{ + if(conn.succeeded()){ + SQLConnection conns=conn.result(); + conns.query(" SELECT id,name FROM auth.test where deleted=false ", query -> { + System.out.println("quert:"+query.cause()); + if (query.failed()) { + sendError(500, response); + } else { + JsonArray arr = new JsonArray(); + query.result().getRows().forEach(arr::add); + System.out.println("quert success"); + response.putHeader("content-type", "application/json").end(arr.encode()); + } + }); + }else{ + System.out.println("fails"); + sendError(500, response); + } + });*/ + JsonArray array=new JsonArray(); + + jdbc.query(vertx, " SELECT id,name FROM auth.test where deleted=false ", array) + .setHandler(xx->{ + Gson gs = new GsonBuilder() + .serializeNulls() + .create(); + if(xx.succeeded()){ + Msg_Vo msg=xx.result(); + + String res=gs.toJson(msg); + + response.putHeader("content-type", "application/json").end(res); + }else{ + Msg_Vo msg=new Msg_Vo(-1, "数据异常"); + String res=gs.toJson(msg); + response.putHeader("content-type", "application/json").end(res); + } + }); + + } + + // 删除 + private void deleteuser(RoutingContext routingContext) { + String id = routingContext.request().getParam("id"); + HttpServerResponse response = routingContext.response(); + if (id == null) { + sendError(400, response); + } else { + JDBCUtil jdbc = new JDBCUtil(); + jdbc.getConnection(vertx).setHandler(conn->{ + SQLConnection conns=conn.result(); + conns.queryWithParams("SELECT id,name FROM auth.test where id = ?", new JsonArray().add(Integer.parseInt(id)), + query -> { + if (query.failed()) { + sendError(500, response); + } else { + if (query.result().getNumRows() == 0) { + sendError(404, response); + } else { + conns.updateWithParams("update auth.test set deleted=true where id=? ", + new JsonArray().add(id), edit -> { + if (edit.failed()) { + sendError(500, routingContext.response()); + } else { + routingContext.response().end(); + } + }); + } + } + }); + }); + + + + } + } + + // 添加 + private void adduser(RoutingContext routingContext) { + + /* + * final Users user = Json.decodeValue(routingContext.getBodyAsString(), + * Users.class); users.put(user.getId(), user); + * routingContext.response().setStatusCode(201).putHeader( + * "content-type", "application/json; charset=utf-8") + * .end(Json.encodePrettily(user)); + */ + + + JsonObject user = routingContext.getBodyAsJson(); + JDBCUtil jdbc = new JDBCUtil(); + jdbc.getConnection(vertx).setHandler(conn->{ + SQLConnection conns=conn.result(); + conns.updateWithParams("INSERT INTO auth.test (name) VALUES (?)", new JsonArray().add(user.getString("name")), + query -> { + System.out.println("username:"+user.getString("name")); + if (query.failed()) { + sendError(500, routingContext.response()); + } else { + routingContext.response().end(); + } + }); + }); + + } + + private void sendError(int statusCode, HttpServerResponse response) { + response.setStatusCode(statusCode).end(); + } + + // 获取 + private void getUser(RoutingContext routingContext) { + String id = routingContext.request().getParam("id"); + HttpServerResponse response = routingContext.response(); + if (id == null) { + sendError(400, response); + } else { + JDBCUtil jdbc = new JDBCUtil(); + jdbc.getConnection(vertx).setHandler(conn->{ + SQLConnection conns=conn.result(); + conns.queryWithParams("SELECT id,name FROM test where id = ?", new JsonArray().add(Integer.parseInt(id)), + query -> { + if (query.failed()) { + sendError(500, response); + } else { + if (query.result().getNumRows() == 0) { + sendError(404, response); + } else { + response.putHeader("content-type", "application/json") + .end(query.result().getRows().get(0).encode()); + } + } + }); + }); + + } + } + + // 修改 + private void updateuser(RoutingContext routingContext) { + + HttpServerResponse response = routingContext.response(); + JsonObject user = routingContext.getBodyAsJson(); + if (user == null || user.getInteger("id") == null) { + sendError(400, response); + } else { + + int id = user.getInteger("id"); + JDBCUtil jdbc = new JDBCUtil(); + jdbc.getConnection(vertx).setHandler(conn->{ + SQLConnection conns=conn.result(); + conns.queryWithParams("SELECT id,name FROM auth.test where id = ?", new JsonArray().add(id), query -> { + if (query.failed()) { + sendError(500, response); + } else { + if (query.result().getNumRows() == 0) { + sendError(404, response); + } else { + conns.updateWithParams("update auth.test set name=? where id=? ", + new JsonArray().add(user.getString("name")).add(id), edit -> { + if (edit.failed()) { + sendError(500, routingContext.response()); + } else { + routingContext.response().end(); + } + }); + } + } + }); + + }); + } + } +} diff --git a/src/main/resources/default-ignite.xml b/src/main/resources/default-ignite.xml new file mode 100644 index 0000000..e2a5494 --- /dev/null +++ b/src/main/resources/default-ignite.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/my/index.html b/src/main/resources/my/index.html new file mode 100644 index 0000000..339479f --- /dev/null +++ b/src/main/resources/my/index.html @@ -0,0 +1,144 @@ + + + + + test + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/src/main/resources/vertx-default-jul-logging.properties b/src/main/resources/vertx-default-jul-logging.properties new file mode 100644 index 0000000..260ed31 --- /dev/null +++ b/src/main/resources/vertx-default-jul-logging.properties @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.impl.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=%t/vertx.log + +.level=INFO +io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +org.apache.ignite.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file diff --git a/target/classes/com/xxxcom/model/Users.class b/target/classes/com/xxxcom/model/Users.class new file mode 100644 index 0000000..c93b5e0 Binary files /dev/null and b/target/classes/com/xxxcom/model/Users.class differ diff --git a/target/classes/com/xxxcom/model/vo/Msg_Vo.class b/target/classes/com/xxxcom/model/vo/Msg_Vo.class new file mode 100644 index 0000000..47ff2b7 Binary files /dev/null and b/target/classes/com/xxxcom/model/vo/Msg_Vo.class differ diff --git a/target/classes/com/xxxcom/util/FileUtil.class b/target/classes/com/xxxcom/util/FileUtil.class new file mode 100644 index 0000000..fe29b9c Binary files /dev/null and b/target/classes/com/xxxcom/util/FileUtil.class differ diff --git a/target/classes/com/xxxcom/util/JDBCUtil.class b/target/classes/com/xxxcom/util/JDBCUtil.class new file mode 100644 index 0000000..b04fa37 Binary files /dev/null and b/target/classes/com/xxxcom/util/JDBCUtil.class differ diff --git a/target/classes/com/xxxcom/xxxproduct/JDBCExample.class b/target/classes/com/xxxcom/xxxproduct/JDBCExample.class new file mode 100644 index 0000000..648484d Binary files /dev/null and b/target/classes/com/xxxcom/xxxproduct/JDBCExample.class differ diff --git a/target/classes/com/xxxcom/xxxproduct/Main.class b/target/classes/com/xxxcom/xxxproduct/Main.class new file mode 100644 index 0000000..82fa0d9 Binary files /dev/null and b/target/classes/com/xxxcom/xxxproduct/Main.class differ diff --git a/target/classes/com/xxxcom/xxxproduct/MyFirstVerticle.class b/target/classes/com/xxxcom/xxxproduct/MyFirstVerticle.class new file mode 100644 index 0000000..1697969 Binary files /dev/null and b/target/classes/com/xxxcom/xxxproduct/MyFirstVerticle.class differ diff --git a/target/classes/com/xxxcom/xxxproduct/XXXSrv.class b/target/classes/com/xxxcom/xxxproduct/XXXSrv.class new file mode 100644 index 0000000..381e4c3 Binary files /dev/null and b/target/classes/com/xxxcom/xxxproduct/XXXSrv.class differ diff --git a/target/classes/default-ignite.xml b/target/classes/default-ignite.xml new file mode 100644 index 0000000..e2a5494 --- /dev/null +++ b/target/classes/default-ignite.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/my/index.html b/target/classes/my/index.html new file mode 100644 index 0000000..339479f --- /dev/null +++ b/target/classes/my/index.html @@ -0,0 +1,144 @@ + + + + + test + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/target/classes/vertx-default-jul-logging.properties b/target/classes/vertx-default-jul-logging.properties new file mode 100644 index 0000000..260ed31 --- /dev/null +++ b/target/classes/vertx-default-jul-logging.properties @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.impl.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=%t/vertx.log + +.level=INFO +io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +org.apache.ignite.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..375d2f2 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Nov 17 17:17:10 CST 2017 +version=1.0.0-SNAPSHOT +groupId=com.xxxcom.xxxproduct +artifactId=xxx-srv diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..b42c82f --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,8 @@ +com\xxxcom\xxxproduct\XXXSrv.class +com\xxxcom\xxxproduct\JDBCExample.class +com\xxxcom\model\Users.class +com\xxxcom\util\FileUtil.class +com\xxxcom\util\JDBCUtil.class +com\xxxcom\xxxproduct\MyFirstVerticle.class +com\xxxcom\model\vo\Msg_Vo.class +com\xxxcom\xxxproduct\Main.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..7e4d95e --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,8 @@ +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\xxxproduct\JDBCExample.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\model\Users.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\xxxproduct\MyFirstVerticle.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\xxxproduct\Main.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\util\FileUtil.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\util\JDBCUtil.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\xxxproduct\XXXSrv.java +D:\javafiles\projects\wykjmv\vertx-demo\src\main\java\com\xxxcom\model\vo\Msg_Vo.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst diff --git a/target/xxx-srv-1.0.0-SNAPSHOT-fat.jar b/target/xxx-srv-1.0.0-SNAPSHOT-fat.jar new file mode 100644 index 0000000..7d326e3 Binary files /dev/null and b/target/xxx-srv-1.0.0-SNAPSHOT-fat.jar differ diff --git a/target/xxx-srv-1.0.0-SNAPSHOT.jar b/target/xxx-srv-1.0.0-SNAPSHOT.jar new file mode 100644 index 0000000..f7b5ccc Binary files /dev/null and b/target/xxx-srv-1.0.0-SNAPSHOT.jar differ -- libgit2 0.24.0