Vert.x is a tool-kit for building reactive applications on the JVM.(Vertx是运行在JVM上用来构建reactive application的工具集)html
500
错误等等)的时候保持响应的能力,因此它必需要为异常处理 而设计。Verticlejava
Vertx部署和运行的代码。Verticles可使用多种语言实现。node
Vert.x Instancereact
Vert.x instance运行在JVM里,Verticle运行在Vert.x instance里。多个Verticles在一个Vert.x instance里异步执行。多个Vert.x instances能够经过Event Bus组成集群。git
Concurrencygithub
Event-based Programming Model安全
使用“事件驱动”的模式去编写代码,采用异步回调handler的方式去处理事件,不能被阻塞!多线程
Event Loops并发
Vert.x的核心线程池,默认每一个Verticle运行在本身的Event Loop线程上,不能被阻塞!app
Message Passing
不一样的Verticle能够经过Event Bus通讯,集群模式下不一样主机上的Verticle也能够经过Event Bus通讯,来实现distributed applications。
Shared data
不一样的Verticle之间能够经过 Shared Data 共享数据。
Verticle 是执行单元,在同一个Vertx实例中能够同时执行多个Verticle。Verticle在event-loop线程上执行,多个Vert.x instances能够在多个host上执行,各个Verticles 经过event bus通讯。
Vert.x 有三种线程池
Acceptor: 用来接收socket链接. 只要有一个服务port须要监听,就会有一个accept线程。
acceptorEventLoopGroup = new NioEventLoopGroup(1, acceptorEventLoopThreadFactory); acceptorEventLoopGroup.setIoRatio(100);
Event Loops: 不断地轮询获取事件,并将获取到的事件分发到对应的事件处理器中进行处理,永远不要阻塞Event Loop线程。
eventLoopThreadFactory = new VertxThreadFactory("vert.x-eventloop-thread-", checker, false, options.getMaxEventLoopExecuteTime()); eventLoopGroup = new NioEventLoopGroup(options.getEventLoopPoolSize(), eventLoopThreadFactory); eventLoopGroup.setIoRatio(NETTY_IO_RATIO);
Worker Threads: Worker线程池,它其实就是一种Fixed Thread Pool:
ExecutorService workerExec = Executors.newFixedThreadPool(options.getWorkerPoolSize(), new VertxThreadFactory("vert.x-worker-thread-", checker, true, options.getMaxWorkerExecuteTime())); PoolMetrics workerPoolMetrics = isMetricsEnabled() ? metrics.createMetrics(workerExec, "worker", "vert.x-worker-thread", options.getWorkerPoolSize()) : null; workerPool = new WorkerPool(workerExec, workerPoolMetrics);
Vert.x 使用 Hazelcast 做为一个In-Memory Data Grid (IMDG). Hazelcast 是一个内嵌的组件。
若是使用集群模式,Vert.x 默认使用Hazelcast来管理在各个不一样Host上的Instance通讯。Hazelcast 也是一种分布式的存储,Hazelcast 是Vert.x Event Bus 在集群模式下的实现基础,也是Vertx分布式共享内存的Shared Map的基础。
split the application into a set of decoupled components providing defined services
把一个应用程序分红各个独立的解耦的组件提供服务。(defined means with a known interface or API)
allow the components communicate with whatever protocol the choose, often REST, but not necessarily 组件之间使用协议通讯,一般是REST。
allow the components use whatever languages and technologies they want 组件能够用不一样的语言和技术实现。
allow each component be developed, released and deployed independently 组件可独立的开发、发布和部署。
allow the deployments be automated in their own pipeline 组件在本身的环境下自动部署。
allow the orchestration of the whole application be reduced to the barest minimum 让整个程序的依赖尽可能最少。
The Micro-Trader Application
The application uses several types of services:
HTTP endpoint (i.e. REST API) - this service is located using an HTTP URL.
Service proxies - these are asynchronous services exposed on the event bus using an RPC interaction mechanism, the service is located using an (event bus) address.
Message sources - these are components publishing messages on the event bus, the service is located using an (event bus) address.
源码:https://github.com/cescoffier/vertx-microservices-workshop
Reference:
http://vertx.io/docs/guide-for-java-devs/
http://vertx.io/docs/vertx-core/java/
https://www.cubrid.org/blog/inside-vertx-comparison-with-nodejs/
https://www.cubrid.org/blog/understanding-vertx-architecture-part-2
https://medium.com/@levon_t/java-vert-x-starter-guide-part-1-30cb050d68aa
https://medium.com/@levon_t/java-vert-x-starter-guide-part-2-worker-verticles-c49866df44ab
http://www.sczyh30.com/vertx-blueprint-microservice/cn/index.html
《Vert.x - From zero to (micro)-hero》http://escoffier.me/vertx-hol/