JUDCon Brazil 2013 - Vert.x an introduction

2,047 views
1,877 views

Published on

JUDCon Brazil 2013 - Vert.x an introduction

  1. 1. Vert.x, an IntroductionClebert SuconicSamuel Tauil
  2. 2. Project Info• 100% open source• Docs and web-site licensed under Creative Commons• Code licensed under ASL 2.0• Top 10 Java projects on githubhttps://github.com/languages/Java/most_watched
  3. 3. What is Vert.x?• General purpose application platform• VMware sponsored OS project• Runs on the JVM• Provides primarily asynchronous APIs• Popular for modern web applications• Solves similar problems as Node.js, Akka, Play…
  4. 4. vert.xFramework to writepolyglot,highly concurrent apps
  5. 5. vert.xFramework to writepolyglot,highly concurrent apps
  6. 6. Javascriptload(vertx.js)vertx.createHttpServer().requestHandler(function(req) {req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>");}).listen(8080, localhost);
  7. 7. Javascriptload(vertx.js)vertx.createHttpServer().requestHandler(function(req) {req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>");}).listen(8080, localhost);$ vertx run example.js –instances 32
  8. 8. Groovyvertx.createHttpServer().requestHandler { req ->req.response.end "<html><body><h1>Hello from vert.x!</h1></body></html>"}.listen(8080, "localhost")$ vertx run example.groovy
  9. 9. Pythonserver = vertx.create_http_server()@server.request_handlerdef handle(req):req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>")server.listen(8080)$ vertx run example.py
  10. 10. Rubyrequire "vertx"include VertxHttpServer.new.request_handler do |req|req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>")end.listen(8080)$ vertx run example.rb
  11. 11. Javaimport org.vertx.java.core.Handler;import org.vertx.java.core.http.HttpServerRequest;import org.vertx.java.platform.Verticle;public class ServerExample extends Verticle {public void start() {vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {public void handle(HttpServerRequest req) {req.response().headers().put("Content-Type", "text/html; charset=UTF-8");req.response().end("<html><body><h1>Hello from vert.x!</h1></body></html>");}}).listen(8080);}}$ vertx run ServerExample.java
  12. 12. vert.xFramework to writepolyglot,highly concurrent apps
  13. 13. Core Concepts• Verticle• vert.x instance• Event bus
  14. 14. Verticles runs insidea vert.x instance.A single vert.x instanceruns inside its ownJVM instance.
  15. 15. Verticles• Are the execution units of vert.x• Mult-language by modules• Application is composed by many verticles• Verticles communicate by message passing• Verticles provide isolation
  16. 16. Event Bus• The nervous system of Vert.x• Verticles communicate using the event bus.• Ultra simple API.• Point to point. Publish/Subscribe.Request/Response.• Pass simple strings, numbers or otherprimitive types.• JSON messages are preferred for structureddata.
  17. 17. Event Bus• Allows verticles to talk each other• Works cross language• Works across the cluster• Spans from server to client side
  18. 18. Event Bus• Register Handlers• Unregister Handlers• Addresses• Messages (transient)
  19. 19. load(vertx.js)var eb = vertx.eventBus;var address = example.addressvar handler = function(message) {stdout.println(Received message + message)}eb.registerHandler(address, handler);function vertxStop() {eb.unregisterHandler(address, handler);}Handler
  20. 20. load(vertx.js)var eb = vertx.eventBus;var address = example.address’vertx.setPeriodic(2000, sendMessage)var count = 0function sendMessage() {var msg = "some-message-" + count++;eb.send(address, msg);stdout.println("sent message " + msg)}Sender
  21. 21. Publish Subscribeeb.publish(‘example.address’, ‘hello world’);
  22. 22. Point to pointeb.send(‘example.address’, ‘hello world’);
  23. 23. Scaling• Scale by creating more Verticle instances• Use message passing to communicate.• Sounds like the Actor Model? Its similar• For TCP and HTTP servers Vert.x willautomatically load-balance
  24. 24. SockJS• Handles the communication between thebrowser and the server.• Provides a websocket-like API in client-side JS• Works when websockets not available• More info at http://sockjs.org
  25. 25. InternalsNetty for network IOJRuby for the Ruby engineGroovyMozilla Rhino for JSJython for Python supportHazelcast for clustering
  26. 26. Future• Scala and Clojure support• Management, including GUI console• Developer experience - IDE integration,testing• Direct-style API using continuations?
  27. 27. http://vertx.io/
  28. 28. Questions?Thankscsuconic@redhat.comsamuel@redhat.com

×