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/