+ All Categories
Home > Technology > Vert.x devoxx london 2013

Vert.x devoxx london 2013

Date post: 10-May-2015
Category:
Upload: pid-ster
View: 3,842 times
Download: 2 times
Share this document with a friend
Description:
vert.x overview at Devoxx UK 2013
Popular Tags:
40
Transcript
Page 1: Vert.x devoxx london 2013
Page 2: Vert.x devoxx london 2013

vert.xasynchronous applications

+ big data

Pid – Stuart WilliamsConsulting Architect

SpringSource

@pidster

Page 3: Vert.x devoxx london 2013

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

Page 4: Vert.x devoxx london 2013

4

vert.x project

Project Lead

@timfox

Committers

@pidster@normanm (netty)

Page 5: Vert.x devoxx london 2013

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

Page 6: Vert.x devoxx london 2013

6

Key Features

Hybrid ReactorPolyglot ContainerTCP/SSL clients and servers

HTTP/HTTPS clients and servers – including WebSockets

File system

Event bus

100% asynchronous

Page 7: Vert.x devoxx london 2013

7

Code!

Super simple HTTP serverServes files by matching request pathOne example for each language

Page 8: Vert.x devoxx london 2013

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)

Page 9: Vert.x devoxx london 2013

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)

Page 10: Vert.x devoxx london 2013

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)

Page 11: Vert.x devoxx london 2013

11

Groovy – groovy-lang.org

vertx.createHttpServer().requestHandler { req ->

def file = req.uri == "/" ? "index.html" : req.uri req.response.sendFile "webroot/$file”

}.listen(8080)

Page 12: Vert.x devoxx london 2013

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);

}

}

Page 13: Vert.x devoxx london 2013

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)

Page 14: Vert.x devoxx london 2013

14

More languages?

DynJS100% InvokeDynamicAlternative to Rhino for JavaScriptNode.js Compatibility for vert.x

Clojure?

What language support do you want see?

Page 15: Vert.x devoxx london 2013

15

Thread Pools

Non-blocking Event LoopsCore LoopAcceptors

BlockingWorker Pool

Page 16: Vert.x devoxx london 2013

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!

Page 17: Vert.x devoxx london 2013

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

Page 18: Vert.x devoxx london 2013

18

Components

Server & ClientTCPHTTP

WebSocketSockJS

Event BusPoint-to-point, publish-subscribeTransparent clustering

Page 19: Vert.x devoxx london 2013

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

Page 20: Vert.x devoxx london 2013

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’ })})

Page 21: Vert.x devoxx london 2013

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

Page 22: Vert.x devoxx london 2013

Modules

Authentication ManagerForm UploadJDBC PersistorMailerMongo PersistorSession Manager

22

■ Web Server■ Work Queue■ AMQP■ More…

Page 23: Vert.x devoxx london 2013

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

});

Page 24: Vert.x devoxx london 2013

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.

Page 25: Vert.x devoxx london 2013

25

Architecture

Separation of concerns Workers if requiredPolyglot

I/O verticles

EventBus

Logicverticles

Workerverticle

Page 26: Vert.x devoxx london 2013

26

Example

….

Page 27: Vert.x devoxx london 2013

27

Big Fast Data

Realtime Analytics Dashboards & APIsWebSocketSockJS

Polyglot IntegrationUse language independent format like JSON, XML for dataExchange messages using event bus

Page 28: Vert.x devoxx london 2013

28

Fast Data – RabbitMQ

AMQP message broker

Use for queuing, routing messages and WAN clustering

Page 29: Vert.x devoxx london 2013

29

Big/Fast Data – Redis

“Data Structure Server”Key-Value storePub-sub messaging

Use for caching verticle data, broadcasting to verticles

Page 30: Vert.x devoxx london 2013

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

Page 31: Vert.x devoxx london 2013

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

Page 32: Vert.x devoxx london 2013

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!

Page 33: Vert.x devoxx london 2013

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

Page 34: Vert.x devoxx london 2013

34

v2.0 – Features

New ClassLoader Netty 4.0 Languages as modules Flexible Module repositories, including Maven Management

Line n

Page 35: Vert.x devoxx london 2013

35

v2.0 – Developer experience

Gradle template project Maven archetype and plugins Zero setup IDE debugging Zero setup IDE testing Test Tools project

Page 36: Vert.x devoxx london 2013

36

Management

Management AgentPublishes metrics on Event Bus in JSON format

Management GUIJMX Demo

Page 37: Vert.x devoxx london 2013

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

Page 38: Vert.x devoxx london 2013

38

Real DeploymentI/O verticles

HTTPJSON RPC

EventBus

Worker Verticles

Spring IntegrationAMQP publisher

Spring Integration (Groovy DSL)AMQP Consumer

HTTPJSON RPC Client

Page 39: Vert.x devoxx london 2013

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

Page 40: Vert.x devoxx london 2013

Q&A


Recommended