Vert.x一些概念
官方使用手册:http://vertx.io/vertx2/manual.html
以2.1.5为例,下载链接:https://bintray.com/vertx/downloads/distribution/2.1.5
http://vertx.io/vertx2/install.html
Vert.x特点
1.多语言,JavaScript, Ruby, Groovy, Java or Python
2.规避多线程编程,使用单线程思维编程(No more synchronized, volatile or explicit locking)
Verticle
Vert.x的一个执行单元,在一个Vert.x实例中可同时执行多个verticles
Module
一个Vert.x应用可包含多个modules,Modules可部署至Maven仓库,可以复用
把应用封装为Module的优点:
Vert.x Instances
A single Vert.x instance runs inside its own JVM instance.
Concurrency
Vert.x框架保证一个verticle实例只在一个线程上运行
Asynchronous Programming Model
异步编程模型,通过事件处理(event handler)实现。For example, to receive data from a TCP socket you set a handler - the handler is then called when data arrives.
Vert.x APIs
container API
部署verticles、modules,verticle配置与日志相关
core API
- TCP/SSL servers and clients
- HTTP/HTTPS servers and clients
- WebSockets servers and clients
- The distributed event bus
- Periodic and one-off timers
- Buffers
- Flow control
- File-system access
- Shared map and sets
- Accessing configuration
- SockJS
可选项
-conf \ json配置文件
-cp \ 资源路劲classpath
-instances \ verticles实例数量
-includes \
-worker 该verticle是否是一个worker verticle
-cluster 支持集群
运行modules 命令:vertx runmod \
运行module使用的是module name,Vertx如何通过module name定位module
- 首先在该module嵌套的module中找
- 在环境变量VERTX_MODS中或mods/下
- 在Vert.x安装路径的sys-mods/下
- 本地不存在则在各种仓库中,仓库从配置在conf/repos.txt中
运行modules zip:vertx runzip \
运行modules fat jar:java -jar
什么是fat jar:http://stackoverflow.com/questions/19150811/what-is-a-fat-jar
Embedding the Vert.x platform
将Vert.x嵌入Java应用中:http://vertx.io/vertx2/embedding_manual.html
Vert.x .platform是运行Vertx modules and verticles的容器,通过org.vertx.java.platform.PlatformManager实现对容器的操作
将Vert.x嵌入Java需要将Vert.x安装目录下lib/所有jar包放至应用classpath下,如果不使用Vert.x集群则不需要hazelcast
使用platform manager需要配置的一些环境变量
vertx.home
vertx.mods
vertx.clusterManagerFactory
配置文件
vertx-platform jar包中有默认的配置文件,若需要覆盖将这些配置文件的classpath配置在vert.x platform jar之前即可
langs.properties : 多语言实现
cluster.xml : 集群相关
repos.txt : modules仓库配置