If you can't read please download the document
Upload
timfox111
View
4.268
Download
1
Embed Size (px)
Citation preview
Dia 1
Vert.x - Polyglot Asynchronous Applications
Tim FoxVert.x Project LeadRed Hat@timfox
What is Vert.x?
General purpose application platform
Superficially similar to Node.js but not a clone!
Asynchronous APIs
Polyglot mix and match Java, JavaScript/CoffeeScript, Ruby, Groovy and Python (others to follow).
Simple but not Simplistic
Part of the new breed of application platforms
Project Info
Independent Community Project
Hopefully moving to the Eclipse Foundation soon!
100% open source (ASL 2.0 + Creative Commons)
9th most watched Java project on github https://github.com/languages/Java/most_watched
Core APIs
TCP/SSL clients and servers
HTTP/HTTPS clients and servers including WebSockets
File system
Event bus
100% asynchronous
Don't call us, we'll call you!
Core APIs
TCP/SSL clients and servers
HTTP/HTTPS clients and servers including WebSockets
File system
Event bus
100% asynchronous
Don't call us, we'll call you!
Basic web-server (JavaScript)
load('vertx.js')
vertx.createHttpServer().requestHandler(function(req) {
var file = req.path === '/' ? 'index.html' : req.path
req.response.sendFile(file)
}).listen(8080)
Why Asynchronous?
Many long lived connections are a feature of modern applications Websockets, MQTT
OS threads are still a precious resource
Need to service many connections with small number of threads
Blocked OS threads means they can't do other work
But async APIs suck, right?
Use promises library like to Flatten the Pyramid of Doom
Threading model
Vert.x implements the Multi-Reactor Pattern
An event loop is an OS thread
Handles events for many handlers
Vert.x has multiple event loops. Typically one per core.
Don't block the event loop!
Hybrid Threading Model
Don't force everything to run on an event loop
Worker verticles can block
Communicate with other verticles by message passing.
Allows us to leverage the huge ecosystem of blocking Java libs
Concurrency
Vert.x components are single-threaded.
Actor-style concurrency.
Move away from 'Java-style' multi-threaded concurrency
No more synchronized, volatile or locking
Wave goodbye to many race conditions
Event Bus
The nervous system of Vert.x
Verticles communicate using the event bus.
Super simple API.
Point to point. Publish/Subscribe. Request/Response.
Pass simple strings, numbers or other primitive types.
JSON messages are preferred for structured data.
Event bus code example
var handler = function(message) {
console.log('Received message ' + message.msg)
}
vertx.eventBus.registerHandler('example.address',
handler)
vertx.setPeriodic(1000, function() {
vertx.eventBus.send('example.address', {msg:'foo'})
})
Distributed Event Bus
Connects multiple Vert.x JVM instances
Forms a large distributed event space
Applications are loosely coupled components distributed across your network
Extend the Event Bus to the Browser
Event bus extends to client side JavaScript too
Uses the same API on the client
Powerful distributed event space spanning both client and server nodes
Ideal for modern real-time web applications
Module system
Verticles can be packaged into re-usable packages called modules
Modules can contain code in any of the Vert.x languages
Modules can live in the usual places. (Vert.x 2.0 - Maven Central, Nexus, etc)
Encourage an eco-system of Vert.x modules.
Empower the community
Keep the core project compact.
Examples of modules
JDBC
MongoDB
Redis
AMQP
Mailer
Work queues
Session Manager
Web framework
Rhino, DynJS, Groovy, JRuby, Jython, Scala, Clojure, etc
Easy Developer Experience
Vert.x 2.0:Gradle template project
Maven archetype and plugins
Zero setup IDE debugging
Zero setup IDE testing
Introducing DynJS
New 100% InvokeDynamic JavaScript implementation for the JVM
Authors part of same polyglot team at Red Hat
DynJS language module for Vert.x
Node.js Compatibility
Run Node.js apps on Vert.x
Node.js support using DynJS
Migration path to Vert.x
+ V8
Vert.x +
Summary
Write apps as set of loosely coupled components that live anywhere
Polyglot use the language(s) you want
Simple concurrency wave goodbye to most race conditions
Leverage existing Java library ecosystem
Module system empower the community
Run Node.js apps too
We believe Vert.x is the platform for the new generation of polyglot web and enterprise applications
Summary
Write apps as set of loosely coupled components that live anywhere
Polyglot use the language(s) you want
Simple concurrency wave goodbye to most race conditions
Leverage existing Java library ecosystem
Module system empower the community
Run Node.js apps too
We believe Vert.x is the platform for the new generation of polyglot web and enterprise applications
Get involved!
Loads more to do
Very small team!
Github: https://github.com/vert-x/vert.x
Google group: vertx
IRC channel: #vertx on freenode.net
https://github.com/vert-x/vert.x
http://vertx.io/
Q&A