vert.x Effortless asynchronous applicationdevelopment for the modern web and              enterprise
Stuart Williams              Pid     Consulting ArchitectSpringSource Division of VMware*        vert.x committer         ...
What is vert.x?•    Polyglot•    Simple•    Scalable•    Asynchronous•    Concurrent
PolyglotWrite application components in:•    JavaScript (+CoffeeScript +AngularJS)•    Ruby•    Python•    Groovy•    Java...
Simple•    ...without being simplistic•    Create real applications in just a few lines of code•    No XML config
Scalable•    Linear horizontal scale•    Uses message passing•    Automatic load-balancing•    Efficiently utilise your se...
Asynchronous•    NIO•    Handlers•    EventBus•    FileSystem•    WebSockets•    SockJS
SockJS●  Handles the communication between the browser  and the server.●  Provides a websocket-like API in client-side JS●...
Concurrency Model●  A verticle instance is single-threaded.●  Move away from Java-style multi-threaded  concurrency●  No m...
Threading Model – Event Loops●  vert.x implements the Multi-Reactor Pattern●  An event loop is an OS thread●  Handles even...
Event Loop != Silver Bullet●  Event loops not the best fit for all types of stuff●  Long running calculations (Fibonacci a...
Hybrid Threading Model●  Dont force everything to run on an event loop●  Worker verticles can block●  Communicate with oth...
Real-time Web Applications●  Modern definition of real-time●  Event bus key technology for real-time web  applications●  F...
Examples
JavaScriptload(vertx.js’)vertx.createHttpServer().requestHandler(function(req) {    var file = req.path === / ? index.html...
Rubyrequire "vertx"Vertx::HttpServer.new.request_handler do |req|  file = req.uri == "/" ? "index.html" : req.uri  req.res...
Pythonimport vertxserver = vertx.create_http_server()@server.request_handlerdef request_handler(req):  file = "index.html"...
Groovyvertx.createHttpServer().requestHandler { req ->    def file = req.uri == "/" ? "index.html" : req.uri    req.respon...
Javaimport org.vertx.java.core.Handler;import org.vertx.java.core.http.HttpServerRequest;import org.vertx.java.deploy.Vert...
Architecture
Classloaders & Messages
Key Dependencies•    Java 7•    Netty•    Hazelcast•    Jackson•    JRuby•    Jython•    Rhino
Key API Methodsvertx.createXXXServervertx.createXXXClientvertx.fileSystemvertx.sharedDatavertx.eventBusvertx.setPeriodicve...
Servers•    NetServer•    HttpServer    –        RouteMatcher    –        ServerWebSocket•    SockJSServer
Clients•    NetClient•    HttpClient    –        WebSocket•    SockJSSocket
EventBuseventBus.send(‘address’, message, replyHandler)eventBus.publish(‘address’, message)•    EventBus Bridge – send mes...
Cluster•    Hazelcast manages event bus address map and    cluster membership•    Explain cache, listeners•    vert.x NetS...
vert.x Applications
Application ComponentsInit Verticle                      Server Verticle                                   EventBus Module...
launcher.groovyvar config = [  address: "org.pidster.foobar.control",  port: 8081]vertx.deployModule(org.pidster.foobar-v1...
Modules•    Authentication Manager•    Form Upload•    JDBC Persistor•    Mailer•    Mongo Persistor•    Session Manager• ...
mod-web-servervar config = [  web_root: <web_root>,  port, <port>,  ssl: <ssl>,  key_store_password: <key_store_password>,...
web + EventBusBridgevar config = [  web_root: <web_root>,  port, <port>,  bridge: true]vertx.deployModule(vertx.web-server...
Module Structure•    Simple structure•    Optional lib dir•    Lazy installation•    Modules can include other modules•   ...
Developing & Testing•    Gradle (or Maven (or Ant!))•    Use a verticle script to launch tests•    Setup Classloader scope...
Best Practice•    Verticle script to manage lifecycle•    Define configuration in JSON•    Compose from modules•    Never ...
What’s next?
Languages•    Languages as modules•    Lazy installation•    Scala•    Clojure
Management•    JMX API•    Publish metrics on EventBus in JSON•    Configurable sample time & filters•    GUI•    github.c...
Developers & API•    IDE support•    Build config and plugins•    Better, easier testing•    More examples•    Promises AP...
Project
Community•    vert.x is Open Source•    Active community•    Contributions welcome•    Module repository is growing
Project•    http://vertx.io•    @timfox – project lead•    @pidster – project lurker•    https://github.com/vert-x•    Goo...
Summary•    Polyglot – use the languages you want•    Simple concurrency – wave goodbye to most    race conditions•    Lev...
Questions?
Upcoming SlideShare
Loading in …5
×

Groovy & Grails eXchange 2012 vert.x presentation

3,724 views

Published on

Effortless asynchronous application development for the modern web and enterprise

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,724
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
54
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Groovy & Grails eXchange 2012 vert.x presentation

  1. 1. vert.x Effortless asynchronous applicationdevelopment for the modern web and enterprise
  2. 2. Stuart Williams Pid Consulting ArchitectSpringSource Division of VMware* vert.x committer @pidster * Correct at time of writing
  3. 3. What is vert.x?• Polyglot• Simple• Scalable• Asynchronous• Concurrent
  4. 4. PolyglotWrite application components in:• JavaScript (+CoffeeScript +AngularJS)• Ruby• Python• Groovy• JavaMix and match several programming languagesin a single app.
  5. 5. Simple• ...without being simplistic• Create real applications in just a few lines of code• No XML config
  6. 6. Scalable• Linear horizontal scale• Uses message passing• Automatic load-balancing• Efficiently utilise your server cores
  7. 7. Asynchronous• NIO• Handlers• EventBus• FileSystem• WebSockets• SockJS
  8. 8. SockJS● Handles the communication between the browser and the server.● Provides a websocket-like API in client-side JS● Works when websockets not available● JSON-Polling, XHR-Polling/Streaming, etc● Similar in some ways to socket.io● More info at http://sockjs.org
  9. 9. Concurrency Model● A verticle instance is single-threaded.● Move away from Java-style multi-threaded concurrency● No more synchronized, volatile or locking● Wave goodbye to many race conditions
  10. 10. Threading Model – Event Loops● 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.● Dont block the event loop!
  11. 11. Event Loop != Silver Bullet● Event loops not the best fit for all types of stuff● Long running calculations (Fibonacci anyone?)● Using blocking APIs – e.g. JDBC● Most traditional Java libs have blocking APIs● … how do we leverage them?
  12. 12. Hybrid Threading Model● Dont 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
  13. 13. Real-time Web Applications● Modern definition of real-time● Event bus key technology for real-time web applications● Focus on sending messages to server components or other browser nodes● Mobile applications, online games● Use vert.x with any JS toolkit.
  14. 14. Examples
  15. 15. JavaScriptload(vertx.js’)vertx.createHttpServer().requestHandler(function(req) { var file = req.path === / ? index.html : req.path; req.response.sendFile(webroot/ + file);}).listen(8080)
  16. 16. Rubyrequire "vertx"Vertx::HttpServer.new.request_handler do |req| file = req.uri == "/" ? "index.html" : req.uri req.response.send_file "webroot/#{file}"end.listen(8080)
  17. 17. Pythonimport vertxserver = vertx.create_http_server()@server.request_handlerdef request_handler(req): file = "index.html" if req.uri == "/" else req.uri req.response.send_file("webroot/%s"%file)server.listen(8080)
  18. 18. Groovyvertx.createHttpServer().requestHandler { req -> def file = req.uri == "/" ? "index.html" : req.uri req.response.sendFile "webroot/$file"}.listen(8080)
  19. 19. 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); }}
  20. 20. Architecture
  21. 21. Classloaders & Messages
  22. 22. Key Dependencies• Java 7• Netty• Hazelcast• Jackson• JRuby• Jython• Rhino
  23. 23. Key API Methodsvertx.createXXXServervertx.createXXXClientvertx.fileSystemvertx.sharedDatavertx.eventBusvertx.setPeriodicvertx.setTimer
  24. 24. Servers• NetServer• HttpServer – RouteMatcher – ServerWebSocket• SockJSServer
  25. 25. Clients• NetClient• HttpClient – WebSocket• SockJSSocket
  26. 26. EventBuseventBus.send(‘address’, message, replyHandler)eventBus.publish(‘address’, message)• EventBus Bridge – send messages direct to JavaScript in web browsers• Messages are strongly typed in Java• JSON in JavaScript• Hash in Python, Ruby
  27. 27. Cluster• Hazelcast manages event bus address map and cluster membership• Explain cache, listeners• vert.x NetServer & NetClient used for comms• Fully configurable network ports• Use SSL for security
  28. 28. vert.x Applications
  29. 29. Application ComponentsInit Verticle Server Verticle EventBus Modules Worker Modules 8 20 Event Loop Worker Pool
  30. 30. launcher.groovyvar config = [ address: "org.pidster.foobar.control", port: 8081]vertx.deployModule(org.pidster.foobar-v1.0, config, 1, { did-> println “deployed with id: $did”})def stop() { // stop & clean up}
  31. 31. Modules• Authentication Manager• Form Upload• JDBC Persistor• Mailer• Mongo Persistor• Session Manager• Web Server• Work Queue• AMQP
  32. 32. mod-web-servervar 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, { did-> // deployed})
  33. 33. web + EventBusBridgevar config = [ web_root: <web_root>, port, <port>, bridge: true]vertx.deployModule(vertx.web-server-v1.0, config, 1, { did-> vertx.registerHandler(some.address, { msg-> println “msg: $msg” }})
  34. 34. Module Structure• Simple structure• Optional lib dir• Lazy installation• Modules can include other modules• mod.json{ “main”:”org.pidster.jdbc.Main”, “worker”: “true”, “includes: “org.pidster-foobar-v1.0”}
  35. 35. Developing & Testing• Gradle (or Maven (or Ant!))• Use a verticle script to launch tests• Setup Classloader scope• vertx-junit-annotationssrc/main/groovysrc/test/groovysrc/vertxInteg/groovy
  36. 36. Best Practice• Verticle script to manage lifecycle• Define configuration in JSON• Compose from modules• Never block the event loop!
  37. 37. What’s next?
  38. 38. Languages• Languages as modules• Lazy installation• Scala• Clojure
  39. 39. Management• JMX API• Publish metrics on EventBus in JSON• Configurable sample time & filters• GUI• github.com/swilliams-vmw/mod-management
  40. 40. Developers & API• IDE support• Build config and plugins• Better, easier testing• More examples• Promises API?• Direct-style API using continuations?
  41. 41. Project
  42. 42. Community• vert.x is Open Source• Active community• Contributions welcome• Module repository is growing
  43. 43. Project• http://vertx.io• @timfox – project lead• @pidster – project lurker• https://github.com/vert-x• Google Group: vertx
  44. 44. Summary• Polyglot – use the languages you want• Simple concurrency – wave goodbye to most race conditions• Leverage existing Java library ecosystem• Powerful distributed event bus which spans client and server• Flexible module system
  45. 45. Questions?

×