Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

vert.x - polyglot - modular - asynchronous

Introduction to the vert.x framework. Talks about modularity, asynchronous processing and the module concept.
by

Eberhard Wolff

on 6 May 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of vert.x - polyglot - modular - asynchronous

vertx
polyglot - asynchronous - modular

Eberhard Wolff
@ewolff
Architecture and Technology Manager
adesso AG

Architecture & Technology Manager at adesso
Speaker
Author
Blog: http://ewolff.com
Twitter: @ewolff
http://slideshare.com/ewolff
http://prezi.com/user/ewolff
About me
vert.x supports
Java
JavaScript (DynJS/ Rhino)
Ruby (JRuby)
Python (Jython)
Groovy
Natural API
vert.x core (Java)
language specific layer
JavaScript Java
fileSystem.writeFile = function(path, data, handler) {
if (typeof data === 'string') {
data = new org.vertx.java.core.buffer.Buffer(data);
}
jfs.writeFile(path, data, wrapHandler(handler));
return fileSystem;
}
vertx run server.HttpServerExample
-cp "classes:mykewlverticle.jar"
public class HttpServerExample 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!</h1></body></html>");
}
}).listen(8080);
}
}
Vertx vertx = VertxFactory.newVertx();
vertx.createHttpServer()
.requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
req.response.headers().set("Content-Type",
"text/html; charset=UTF-8");
req.response()
.end("<html><body><h1>Hello!</h1></body></html>");
}
}).listen(8080);
Event
Event
Event
Event
Event
Event
Event
Loop
=
Thread
Asynchronous Processing
in a Nutshell
One thread - many network connections
# Event Loop = # CPU cores
Do not block the Event Loop!
Worker outside Event Loop
for long running operations
Verticles
Smallest components for vert.x
vertx run HttpServerExample.java
vertx run HttpServerExample.js
-instances 10
-cluster
Modules
JavaScript
var vertx = require('vertx')

vertx.createHttpServer()
.requestHandler(function(req) {
req.response.headers().set('Content-Type',
'text/html; charset=UTF-8');
req.response.end(
'<html><body><h1>Hallo!</h1></body></html>');
}).listen(8080);
<rant>
...
</rant>
public class RestServer
extends Verticle {
...
}
{
"main": "server.RestServer"
}
start via command line
vertx runmod com.ewolff~rest-server~0.0.1
deploy in code:
vertx.deployModule('com.ewolff~rest-server~0.0.1');
How can modules
exchange information?
Shared data
Shared Maps or Sets
May only store immutable data (String, Integer, ...)
Immutable - No concurrency issues
Limited scaling
Event Bus
Verticle
Verticle
Verticle
Point 2 point & publish / subscribe
JSON
Let's store some JSON
data in
JsonObject mongoPersistorConfig = new JsonObject()
.putString("address", "vertx.mongopersistor");
.putString("db_name", "test_db");

container.deployModule(
"io.vertx~mod-mongo-persistor~2.0.0-final",
mongoPersistorConfig, 1);
Deploy MongoDB Module
JsonObject command = new JsonObject()
.putString("action", "save")
.putString("collection", "customers")
.putObject("document", data);

vertx.eventBus().send("vertx.mongopersistor", command,
new Handler<Message<JsonObject>>() {
public void handle(Message<JsonObject> mongoReply) {
...
}
});
JsonObject command = new JsonObject()
.putString("action", "findone")
.putString("collection", "customers")
.putObject("matcher",
new JsonObject().putString("_id","42"));

vertx.eventBus().send("vertx.mongopersistor", command,
new Handler<Message<JsonObject>>() {
public void handle(Message<JsonObject> reply) {
JsonObject found = reply.body().getObject("result");
}
});
var eb = vertx.eventBus;
eb.send('vertx.mongopersistor', {
action : 'findone',
collection : 'customer',
matcher : {
"_id" : 42
}
}, function(reply) {
var found = reply.result;
});
Event Bus
fits asynchronous model
Decoupling: only data - no method calls
Can be distributed
JSON - support polyglot modules
vert.x Module Concept
Independent deployment easily possible
JSON data - no shared classes
Have you ever tried to deploy modules independly in Java EE?
Feature
TCP/SSL
WebSockets
SockJS
MongoDB
JDBC
Redis
Memcached
Mailer
Maven PlugIn
Testtool for in-container testing
Openshift support
Web Server
Session Manager
Shell
Auth manager
Work Queue
Modules
Tools
Scala (post 2.0)
Coffeescript
Save
Find
Find in JavaScript
Links
http://vertx.io/tutorials.html
https://github.com/vert-x
https://github.com/vert-x/vertx-gradle-template
https://github.com/vert-x/vertx-maven
http://www.infoq.com/news/2013/05/high-volume-vertx
http://www.heise.de/developer/artikel/vert-x-asynchrones-und-Event-getriebenes-Java-Webframework-1587065.html
http://jaxenter.de/artikel/vertx-alles-wird-alles
{
"rant" :
"Anonymous Inner Classes are a
sorry replacement for closures"
}
Details
2.0.1
Apache 2.0 license
Eclipse project
Developers from Red Hat and Pivotal
Embedded vert.x
Xtend
Clojure (post 2.0)
Full transcript