vert.x devoxx london 2013
Post on 10-May-2015
3.843 Views
Preview:
DESCRIPTION
TRANSCRIPT
vert.xasynchronous applications
+ big data
Pid – Stuart WilliamsConsulting Architect
SpringSource
@pidster
3
Pid (Stuart Williams)
Speaker Bio■ Consulting Architect at SpringSource / Pivotal
Application architecture, performance (and hand-waving)
■ Projects■ vert.x■ Apache Oltu (OAuth)
■ Communities■ Apache Tomcat■ Groovy
4
vert.x project
Project Lead
@timfox
Committers
@pidster@normanm (netty)
5
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
6
Key Features
Hybrid ReactorPolyglot ContainerTCP/SSL clients and servers
HTTP/HTTPS clients and servers – including WebSockets
File system
Event bus
100% asynchronous
7
Code!
Super simple HTTP serverServes files by matching request pathOne example for each language
8
JavaScript – Mozilla Rhino
load('vertx.js’)
vertx.createHttpServer().requestHandler(function(req) {
var file = req.path === '/' ? 'index.html' : req.path; req.response.sendFile('webroot/' + file);
}).listen(8080)
9
Python – www.jython.org
import vertx
server = vertx.create_http_server()@server.request_handler
def request_handler(req): file = "index.html" if req.uri == "/" else req.uri req.response.send_file("webroot/%s"%file)server.listen(8080)
10
Ruby – jruby.org
require "vertx"
Vertx::HttpServer.new.request_handler do |req|
file = req.uri == "/" ? "index.html" : req.uri req.response.send_file "webroot/#{file}”
end.listen(8080)
11
Groovy – groovy-lang.org
vertx.createHttpServer().requestHandler { req ->
def file = req.uri == "/" ? "index.html" : req.uri req.response.sendFile "webroot/$file”
}.listen(8080)
12
Javaimport org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;
public class Server extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
String file = req.path.equals("/") ? "index.html" : req.path;
req.response.sendFile("webroot/" + file);
}
}).listen(8080);
}
}
13
Scala – soon!
vertx.createHttpServer .requestHandler { req: HttpServerRequest =>
val file : String = if (req.path == “/”) “/index.html” else req.uri req.response.sendFile("webroot/" + file)
} .listen(8080)
14
More languages?
DynJS100% InvokeDynamicAlternative to Rhino for JavaScriptNode.js Compatibility for vert.x
Clojure?
What language support do you want see?
15
Thread Pools
Non-blocking Event LoopsCore LoopAcceptors
BlockingWorker Pool
16
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!
17
Hybrid Threading ModelDon't force everything to run on an event loopWorker verticles can blockCommunicate with other verticles by message passing.Allows us to leverage the huge ecosystem of blocking Java libs
18
Components
Server & ClientTCPHTTP
WebSocketSockJS
Event BusPoint-to-point, publish-subscribeTransparent clustering
19
Event Bus
The nervous system of Vert.xVerticles 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.Transparent clustering
20
Event Bus – 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’ })})
21
Event Bus – Extended to Browser
Event bus extends to client side JavaScript tooUses the same API on the clientPowerful distributed event space spanning both client
and server nodesIdeal for modern “real-time” web applications
Modules
Authentication ManagerForm UploadJDBC PersistorMailerMongo PersistorSession Manager
22
■ Web Server■ Work Queue■ AMQP■ More…
23
mod-web-serverload('vertx.js’)
var config = {
"web_root": <web_root>,
"port", <port>,
"ssl": <ssl>,
"key_store_password": <key_store_password>,
"key_store_path": <key_store_path>,
}
vertx.deployModule('vertx.web-server-v1.0', config, 1, function() {
// deployed
});
24
Composition
Deploy code using codeModules are unit of composed codeDeploy modules using a verticleOr provide multiple verticles inside a moduleRemember: verticles communicate using the Event Bus.
25
Architecture
Separation of concerns Workers if requiredPolyglot
I/O verticles
EventBus
Logicverticles
Workerverticle
26
Example
….
27
Big Fast Data
Realtime Analytics Dashboards & APIsWebSocketSockJS
Polyglot IntegrationUse language independent format like JSON, XML for dataExchange messages using event bus
28
Fast Data – RabbitMQ
AMQP message broker
Use for queuing, routing messages and WAN clustering
29
Big/Fast Data – Redis
“Data Structure Server”Key-Value storePub-sub messaging
Use for caching verticle data, broadcasting to verticles
30
Big/Fast Data – GemFire
Compute Grid / Distributed CacheEmbeddable Key-Value store
Use for large partitioned caches, high performance compute, WANs
Send data to vert.x using CacheListeners, subscriptions, AsyncQueues
31
Big Data – Hadoop
Hive – of course!SQL queries via JDBC worker verticleStandard pattern via event bus
Use for ad-hoc queries on large datasets
32
Big Data – MQTT
MQTT is a machine-to-machine (M2M) / "Internet of Things” connectivity protocol.
Extremely lightweight publish/subscribe messaging transport.
It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.
Eclipse Paho
Coming soon!
33
Big Data – Intravert (@zznate - apigee)
Processors, filters and procedures allow you perform arbitrary programmatic transformations on the server side before the results are returned to the client.
Execute procedures and join like logic in a single RPC request eliminating round-trips
A simple transport and JSON API that runs over HTTP allows clients to choose from JSON, JSON compressed by smile, & even big fat sexy XML
A real REST interface (ever thought about what would a Cassandra hyper media API look like?)
Work with simple familiar objects like String or Integer instead of bytes
34
v2.0 – Features
New ClassLoader Netty 4.0 Languages as modules Flexible Module repositories, including Maven Management
Line n
35
v2.0 – Developer experience
Gradle template project Maven archetype and plugins Zero setup IDE debugging Zero setup IDE testing Test Tools project
36
Management
Management AgentPublishes metrics on Event Bus in JSON format
Management GUIJMX Demo
37
Real Deployment
vert.x provides a JSON RPC API:
deployer.js JsonRpcServer.groovy Integration.groovy – worker Spring Integration message flow to RabbitMQ
Dynamically deploys components to consume queues: Consumer.groovy – worker, Spring Integration message
flow JsonRpcClient.groovy
38
Real DeploymentI/O verticles
HTTPJSON RPC
EventBus
Worker Verticles
Spring IntegrationAMQP publisher
Spring Integration (Groovy DSL)AMQP Consumer
HTTPJSON RPC Client
39
Summary
Write apps as set of loosely coupled components that live anywhere
Polyglot – use the language(s) you wantSimple concurrency – wave goodbye to most race
conditionsLeverage existing Java library ecosystemModule system – empower the communityRun Node.js apps too
We believe Vert.x is the platform for the new generation of polyglot web and enterprise applications
Q&A
top related