際際滷

際際滷Share a Scribd company logo
Vert.x  asinkroni,
skalabilni i poliglotni
framework nove generacije

Mihovil Rister
Razvojni in転enjer
@ Pet Minuta d.o.o.
Sadr転aj predavanja









Vert.x  邸to je to?
Karakteristike
Osnovne komponente
Arhitektura
Uporaba
Usporedba
Najbolje prakse
Zakljuak
Vert.x  邸to je to ?








Zapravo i nije framework, vi邸e kao platforma na JVM
Prva verzija u svibnju 2012. g. (Node.js, 2009. g.)
Inicijalno projekt zaposlenika VMwarea
8. 2013 - Eclipse Foundation (Incubating)
JDK 1.7 +
Jedan od najzanimljivijih projekata na GitHubu
Skalabilan, poliglotan, modularan, asinkron,
jednostavan
Vert.x  tko je to ?

Tim Fox
http://vertx.io/
Vert.x  邸to je to ?
 Koji problem rje邸ava?
 C10K !
 It's time for web servers to handle ten thousand
clients simultaneously, don't you think? After all, the
web is a big place now. Dan Kegel (2003.)
 Upravljanje i optimiranje resursima pri velikom broju
simultanih korisnika (konekcija).
 Thread po konekciji? Blokirajue operacije?
 Vert.x - asnikrona i event driven arhitektura
Vert.x  Karakteristike
 Poliglotan (JS, Java, Python, Groovy, Ruby  Scala i
Clojure dolaze)
 Asinkron (zapravo event driven)
 Modularan (koristi module i mo転e biti modul)
 Jednostavan (bez puno konfiguracije)
 Skalabilan (koristi sabirnicu za komunikaciju)
 Jednostavan model vi邸enitnosti (multithreading,
Reactor pattern)
 Embedabilan i koristi sve prednosti JVM-a
Vert.x  Osnovne komponente
 Vertica (Verticle)
 Vert.x instanca

 (Distribuirana) sabirnica dogaaja (Event bus)
 Modul
Vert.x  Osnovne komponente - Vertica





Osnovna jedinica upravljanja (deploymenta)
Kod koji Vert.x izvr邸ava
Izolirani ClassLoader
Ne mogu globalno dijeliti stanje (static, globalne
varijable,...)
 2 tipa vertica:
1. Logika vertica - single threading  non blocking code
2. Radna vertica (Worker verticle)  mo転e korisiti multithreading i
kod koji blokira (nije asinkron)
Vert.x  Vertica u Javi
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.platform.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);
}
}
$vertx run Server.java
Vert.x  Vertica u Javi 8 + Lambda
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;
public class Server extends Verticle {
@Override
public void start() throws Exception {
vertx.createHttpServer().requestHandler((HttpServerRequest req) -> {
String file = req.path.equals("/") ? "index.html" : req.path;
req.response().sendFile(file);
}).listen(8086);
}
}
$vertx run Server.java
Vert.x  Osnovne komponente - Vert.x instanca
 Jedna ili vi邸e vertica
 Radi u vlastitoj JVM instanci
 Vi邸e instanci na istom hostu (vi邸e hostova koji
komuniciraju putem distribuiranog Event busa)
 Garantirano: Vert.x instancu izvr邸ava samo jedan
thread (singlethreading programiranje)
 Odr転ava set threadova za:
 Event (Run) Loop (1 po CPU jezgri)
 thread pool za izvr邸avanje radnih vertica
Vert.x  Osnovne komponente -Vert.x instanca
Event Loops

Quad Core CPU

$vertx run Server.java instances 4
Vert.x  Osnovne komponente  Event Bus








貼ivani sustav Vert.x-a
Komunikacija izmeu vertica (meu procesna)
Zbilja jednostavan API
Pub/Sub, Req/Resp, PtoP naini prosljeivanja poruka
JSON poruke za strukturirane podatke
Distribuirani: spaja Vert.x JVM instance
Do klijentske strane (npr. Browser + SocksJS ili Web
Socket)
 Nije perzistentan (in memory)
Vert.x  Osnovne komponente  Event Bus
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.EventBus;
...
Handler<Message<String>> myHandler = new Handler<Message<String>>() {
public void handle(Message<String> message) {
System.out.println("Primih poruku: " + message.body);
// izvr邸i neophodne radnje
message.reply(Odgovor");
}
};
//----------------------------------------------------------------------------------------------------------------eb.registerHandler("test.address", myHandler);
eb.send("test.address", "Ovo je poruka", new Handler<Message<String>>() {
public void handle(Message<String> message) {
System.out.println("Primih odgovor: " + message.body);
}
});
Vert.x  Osnovne komponente - Modul
 Mod  upakirana Vert.x aplikacija
 Module koriste druge aplikacije ili drugi Vert.x sustavi
 Idealno za distribuciju putem Mavena (Nexus)
 Vert.x javni registar modula - http://modulereg.vertx.io/
 Busmod  modul koji komunicira preko EventBusa s
verticama putem JSON poruka.
 Moduli su preferiran nain kori邸tenja i embedanja Vert.x
aplikacija
Vert.x  Osnovne komponente - Modul
 Primjeri:
 mod-mongo-peristor, mod-redis, mod-jdbc-persistor, modpostresql,...
 mod-mailer, mod-session-manager, mod-auth-mgr
 mod-guice, mod-spring-appcontext
 mod-kafka, mod-jersey, mod-socketio
 mod-zip, mod-unzip, mod-ampq

 Jezici koje vert.x podr転ava su takoer moduli:
 mod-lang-rhino, mod-lang-groovy, mod-lang-jython, mod-langjruby, mod-lang-scala, mod-lang-coljure, ...
Vert.x  Arhitektura
Vert.x  Arhitektura (distribuirana sab.)
Vert.x  Arhitektura
 Dijeljenje podataka izmeu vertica (Shared state):
 Vertice mogu djeliti nepromjenjive podatke (Immutabe)
 Sesija po Vert.x instanci
 Vert.x daje pristup Shared Map i Shared Set
 Samo jednostavni tipovi: brojevi, boolean, String i Buffer
 Bitno za npr. Cache, sinkronizacijsku logiku, otvorene
konekcije i sl.
Vert.x  Arhitektura
 Primjer dijeljene mape
ConcurrentMap<String, Integer> map = vertx.sharedData().getMap("app.my-data");
map.put("key1", 123);
map.putIfAbsent("key1", 123);
map.replace("key1", 123, 124);
map.get("key1");
map.remove("key1");
Vert.x  Arhitektura
 Primjer dijeljenog seta
Set<String> set = vertx.sharedData().getSet("app.may-set");
set.add("Mihovil");
set.contains("Mihovil");
vertx.removeSet("app.may-set");
Vert.x  Arhitektura
 Concurrency model:






Multi-reactor pattern
Synchronised, volatile, locking
Single threaded kod po vertici
Hibridni multithreading (logika i worker vertica)
Izolirani ClassLoader i jedan thread/event loop za egzekuciju

 Asinkroni model programiranja:
 Event handleri
 Asinkroni API za filesystem i streamove
 Izmjena poruka putem sabirnice
Vert.x  Arhitektura
Vert.x interno koristi ove open source projekte:
 Netty 4.0 -> network IO
 JRuby -> Ruby engine
 Jython -> Python engine
 Mozilla Rhino -> JavaScript engine
 Hazelcast -> upravljanje grupama i klasterom
 Jackson -> za JSON
 ...
Vert.x  Uporaba
 Maven:
<dependency>
<dependency>
<groupId>io.vertx</groupId>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<artifactId>mod-mongo-persistor</artifactId>
<version>2.0.2-final</version>
<version>2.0.0-final</version>
</dependency>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>2.0.2-final</version>
</dependency>
mvn archetype:generate -Dfilter=io.vertx: -DgroupId=com.mycompany -DartifactId=my-module
-Dversion=0.1
Vert.x  Usporedba
Vert.x

Node.js

Polyglot

JavaScript

Lakoa skaliranja i klasteriranja

Nije tako lako skalirati

Skromniji broj modula

Velik broj modula

Dobra dokumentacija

Dobra dokumentacija

Bolje perfromanse

Ne tako dobre performanse (u odnosu na
Java vert.x)

Malo primjera uporabe

Puno primjera uporabe

Mali community

Velik community

Lak邸e ukljuivanje u Java projekte i
iskori邸tavanje Java ekosustava

Nije esto kori邸ten za enterprise sustave
Vert.x  Usporedba
 Programerska perspektiva :
 Dobre stvari:






JAVA !
Jednostavan i neop邸iran API
Timovi za razvoj u raznim jezicima
Zero conf. debugiranje i testiranje (podr邸ka za integracijske testove)
Container API (programsko deplojanje i undeplojanje te logiranje)

 Ne tako dobre:
 Dosta anonimnih unutarnjih klasa (Lambdas to the rescue!)
 Nativne extenzije na drugim platformama na koje su ljudi navikli
 Nezgodno debugiranje busmoda (stack trace zavr邸ava kod izmjene
poruka)
 Nema (out of the box) MVC podr邸ku
 JDK7+ pa nema Androida
Vert.x  Najbolje prakse










Dont block the event loop!
Java za razvoj (najbolje performanse)
Dobar alat za odreene vrste poslova, ne sve.
Po邸tedno kori邸tenje worker vertica.
Koristiti asinkrone java biblioteke (ako je mogue)
JCA adapter za integraciju s J2EE
Koristiti i dijeliti module (javni registar)
Autodeploy kod razvoja, no mo転da ne i u produkciji 
Pratiti mre転ni promet na hostu (tuniranje performansi)
Vert.x  Nabolje preporuke
 Koristiti za:
 Real time aplikacije (gdje biste i Node.js)
 Integraciju sa sustavima baziranim na messaging arhitekturi
(AMPQ, ZeroMQ, ...)
 Dashboardi i vezani API (big data)
 Message brokeri
 Push sustavi (push notifikacije za mobile)
 Veliki, particionirani cache sustavi
 Nadgledanje i upravljanje jobovima (Quartz, Jenkins, Hadoop)
 RPC sustavi, ad-hoc upiti nad velikim datasetovima
 Streaming podataka, audio-video, on the fly transformacije pod.
Vert.x  Zakljuak
 Open source governance je bitan !
 Projekt je jo邸 mlad i u razvitku
 Nedostaje pravih, kompleksnih primjera
primjene u produkciji
 I u Java svijet dolaze nove vrste platforma, za
moderne izazove
 Poliglotnost: izrada kompleksnih modernih
enterprise sustava
Kontakt
Mihovil Rister

gsm

+385 91 5865 907

Razvojni in転enjer,

mail

mihovil.rister@fiveminutes.eu

Pet Minuta d.o.o.

skype

mihovil.rister

web

http://www.fiveminutes.eu
Ad

Recommended

Javantura Zagreb 2014 - Vert.x 1.3 - Mihovil Rister
Javantura Zagreb 2014 - Vert.x 1.3 - Mihovil Rister
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Javantura Zagreb 2014 - Alfresco-Neo4j integracija - Damir Murat
Javantura Zagreb 2014 - Alfresco-Neo4j integracija - Damir Murat
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Javantura Zagreb 2014 - Java na klijenstskoj strani - Ivan Vuak
Javantura Zagreb 2014 - Java na klijenstskoj strani - Ivan Vuak
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Panel diskusija - usporedba Web frameworka (IT Showoff)
Panel diskusija - usporedba Web frameworka (IT Showoff)
IT Showoff
JavaCro'15 - Java parallelization - Zlatko Siroti
JavaCro'15 - Java parallelization - Zlatko Siroti
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Javantura Zagreb 2014 - WildFly 8 - Toma転 Cerar
Javantura Zagreb 2014 - WildFly 8 - Toma転 Cerar
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Javantura Zagreb 2014 - universAAL - Andrej Grguri
Javantura Zagreb 2014 - universAAL - Andrej Grguri
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Javantura Zagreb 2014 - Nashorn - Miroslav Re邸etar
Javantura Zagreb 2014 - Nashorn - Miroslav Re邸etar
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC

More Related Content

Featured (20)

2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray

Vert.x - asinkroni skalabilni i poliglotni framework nove generacije

  • 1. Vert.x asinkroni, skalabilni i poliglotni framework nove generacije Mihovil Rister Razvojni in転enjer @ Pet Minuta d.o.o.
  • 2. Sadr転aj predavanja Vert.x 邸to je to? Karakteristike Osnovne komponente Arhitektura Uporaba Usporedba Najbolje prakse Zakljuak
  • 3. Vert.x 邸to je to ? Zapravo i nije framework, vi邸e kao platforma na JVM Prva verzija u svibnju 2012. g. (Node.js, 2009. g.) Inicijalno projekt zaposlenika VMwarea 8. 2013 - Eclipse Foundation (Incubating) JDK 1.7 + Jedan od najzanimljivijih projekata na GitHubu Skalabilan, poliglotan, modularan, asinkron, jednostavan
  • 4. Vert.x tko je to ? Tim Fox http://vertx.io/
  • 5. Vert.x 邸to je to ? Koji problem rje邸ava? C10K ! It's time for web servers to handle ten thousand clients simultaneously, don't you think? After all, the web is a big place now. Dan Kegel (2003.) Upravljanje i optimiranje resursima pri velikom broju simultanih korisnika (konekcija). Thread po konekciji? Blokirajue operacije? Vert.x - asnikrona i event driven arhitektura
  • 6. Vert.x Karakteristike Poliglotan (JS, Java, Python, Groovy, Ruby Scala i Clojure dolaze) Asinkron (zapravo event driven) Modularan (koristi module i mo転e biti modul) Jednostavan (bez puno konfiguracije) Skalabilan (koristi sabirnicu za komunikaciju) Jednostavan model vi邸enitnosti (multithreading, Reactor pattern) Embedabilan i koristi sve prednosti JVM-a
  • 7. Vert.x Osnovne komponente Vertica (Verticle) Vert.x instanca (Distribuirana) sabirnica dogaaja (Event bus) Modul
  • 8. Vert.x Osnovne komponente - Vertica Osnovna jedinica upravljanja (deploymenta) Kod koji Vert.x izvr邸ava Izolirani ClassLoader Ne mogu globalno dijeliti stanje (static, globalne varijable,...) 2 tipa vertica: 1. Logika vertica - single threading non blocking code 2. Radna vertica (Worker verticle) mo転e korisiti multithreading i kod koji blokira (nije asinkron)
  • 9. Vert.x Vertica u Javi import org.vertx.java.core.Handler; import org.vertx.java.core.http.HttpServerRequest; import org.vertx.java.platform.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); } } $vertx run Server.java
  • 10. Vert.x Vertica u Javi 8 + Lambda import org.vertx.java.core.http.HttpServerRequest; import org.vertx.java.deploy.Verticle; public class Server extends Verticle { @Override public void start() throws Exception { vertx.createHttpServer().requestHandler((HttpServerRequest req) -> { String file = req.path.equals("/") ? "index.html" : req.path; req.response().sendFile(file); }).listen(8086); } } $vertx run Server.java
  • 11. Vert.x Osnovne komponente - Vert.x instanca Jedna ili vi邸e vertica Radi u vlastitoj JVM instanci Vi邸e instanci na istom hostu (vi邸e hostova koji komuniciraju putem distribuiranog Event busa) Garantirano: Vert.x instancu izvr邸ava samo jedan thread (singlethreading programiranje) Odr転ava set threadova za: Event (Run) Loop (1 po CPU jezgri) thread pool za izvr邸avanje radnih vertica
  • 12. Vert.x Osnovne komponente -Vert.x instanca Event Loops Quad Core CPU $vertx run Server.java instances 4
  • 13. Vert.x Osnovne komponente Event Bus 貼ivani sustav Vert.x-a Komunikacija izmeu vertica (meu procesna) Zbilja jednostavan API Pub/Sub, Req/Resp, PtoP naini prosljeivanja poruka JSON poruke za strukturirane podatke Distribuirani: spaja Vert.x JVM instance Do klijentske strane (npr. Browser + SocksJS ili Web Socket) Nije perzistentan (in memory)
  • 14. Vert.x Osnovne komponente Event Bus import org.vertx.java.core.Handler; import org.vertx.java.core.eventbus.EventBus; ... Handler<Message<String>> myHandler = new Handler<Message<String>>() { public void handle(Message<String> message) { System.out.println("Primih poruku: " + message.body); // izvr邸i neophodne radnje message.reply(Odgovor"); } }; //----------------------------------------------------------------------------------------------------------------eb.registerHandler("test.address", myHandler); eb.send("test.address", "Ovo je poruka", new Handler<Message<String>>() { public void handle(Message<String> message) { System.out.println("Primih odgovor: " + message.body); } });
  • 15. Vert.x Osnovne komponente - Modul Mod upakirana Vert.x aplikacija Module koriste druge aplikacije ili drugi Vert.x sustavi Idealno za distribuciju putem Mavena (Nexus) Vert.x javni registar modula - http://modulereg.vertx.io/ Busmod modul koji komunicira preko EventBusa s verticama putem JSON poruka. Moduli su preferiran nain kori邸tenja i embedanja Vert.x aplikacija
  • 16. Vert.x Osnovne komponente - Modul Primjeri: mod-mongo-peristor, mod-redis, mod-jdbc-persistor, modpostresql,... mod-mailer, mod-session-manager, mod-auth-mgr mod-guice, mod-spring-appcontext mod-kafka, mod-jersey, mod-socketio mod-zip, mod-unzip, mod-ampq Jezici koje vert.x podr転ava su takoer moduli: mod-lang-rhino, mod-lang-groovy, mod-lang-jython, mod-langjruby, mod-lang-scala, mod-lang-coljure, ...
  • 18. Vert.x Arhitektura (distribuirana sab.)
  • 19. Vert.x Arhitektura Dijeljenje podataka izmeu vertica (Shared state): Vertice mogu djeliti nepromjenjive podatke (Immutabe) Sesija po Vert.x instanci Vert.x daje pristup Shared Map i Shared Set Samo jednostavni tipovi: brojevi, boolean, String i Buffer Bitno za npr. Cache, sinkronizacijsku logiku, otvorene konekcije i sl.
  • 20. Vert.x Arhitektura Primjer dijeljene mape ConcurrentMap<String, Integer> map = vertx.sharedData().getMap("app.my-data"); map.put("key1", 123); map.putIfAbsent("key1", 123); map.replace("key1", 123, 124); map.get("key1"); map.remove("key1");
  • 21. Vert.x Arhitektura Primjer dijeljenog seta Set<String> set = vertx.sharedData().getSet("app.may-set"); set.add("Mihovil"); set.contains("Mihovil"); vertx.removeSet("app.may-set");
  • 22. Vert.x Arhitektura Concurrency model: Multi-reactor pattern Synchronised, volatile, locking Single threaded kod po vertici Hibridni multithreading (logika i worker vertica) Izolirani ClassLoader i jedan thread/event loop za egzekuciju Asinkroni model programiranja: Event handleri Asinkroni API za filesystem i streamove Izmjena poruka putem sabirnice
  • 23. Vert.x Arhitektura Vert.x interno koristi ove open source projekte: Netty 4.0 -> network IO JRuby -> Ruby engine Jython -> Python engine Mozilla Rhino -> JavaScript engine Hazelcast -> upravljanje grupama i klasterom Jackson -> za JSON ...
  • 24. Vert.x Uporaba Maven: <dependency> <dependency> <groupId>io.vertx</groupId> <groupId>io.vertx</groupId> <artifactId>vertx-core</artifactId> <artifactId>mod-mongo-persistor</artifactId> <version>2.0.2-final</version> <version>2.0.0-final</version> </dependency> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-platform</artifactId> <version>2.0.2-final</version> </dependency> mvn archetype:generate -Dfilter=io.vertx: -DgroupId=com.mycompany -DartifactId=my-module -Dversion=0.1
  • 25. Vert.x Usporedba Vert.x Node.js Polyglot JavaScript Lakoa skaliranja i klasteriranja Nije tako lako skalirati Skromniji broj modula Velik broj modula Dobra dokumentacija Dobra dokumentacija Bolje perfromanse Ne tako dobre performanse (u odnosu na Java vert.x) Malo primjera uporabe Puno primjera uporabe Mali community Velik community Lak邸e ukljuivanje u Java projekte i iskori邸tavanje Java ekosustava Nije esto kori邸ten za enterprise sustave
  • 26. Vert.x Usporedba Programerska perspektiva : Dobre stvari: JAVA ! Jednostavan i neop邸iran API Timovi za razvoj u raznim jezicima Zero conf. debugiranje i testiranje (podr邸ka za integracijske testove) Container API (programsko deplojanje i undeplojanje te logiranje) Ne tako dobre: Dosta anonimnih unutarnjih klasa (Lambdas to the rescue!) Nativne extenzije na drugim platformama na koje su ljudi navikli Nezgodno debugiranje busmoda (stack trace zavr邸ava kod izmjene poruka) Nema (out of the box) MVC podr邸ku JDK7+ pa nema Androida
  • 27. Vert.x Najbolje prakse Dont block the event loop! Java za razvoj (najbolje performanse) Dobar alat za odreene vrste poslova, ne sve. Po邸tedno kori邸tenje worker vertica. Koristiti asinkrone java biblioteke (ako je mogue) JCA adapter za integraciju s J2EE Koristiti i dijeliti module (javni registar) Autodeploy kod razvoja, no mo転da ne i u produkciji Pratiti mre転ni promet na hostu (tuniranje performansi)
  • 28. Vert.x Nabolje preporuke Koristiti za: Real time aplikacije (gdje biste i Node.js) Integraciju sa sustavima baziranim na messaging arhitekturi (AMPQ, ZeroMQ, ...) Dashboardi i vezani API (big data) Message brokeri Push sustavi (push notifikacije za mobile) Veliki, particionirani cache sustavi Nadgledanje i upravljanje jobovima (Quartz, Jenkins, Hadoop) RPC sustavi, ad-hoc upiti nad velikim datasetovima Streaming podataka, audio-video, on the fly transformacije pod.
  • 29. Vert.x Zakljuak Open source governance je bitan ! Projekt je jo邸 mlad i u razvitku Nedostaje pravih, kompleksnih primjera primjene u produkciji I u Java svijet dolaze nove vrste platforma, za moderne izazove Poliglotnost: izrada kompleksnih modernih enterprise sustava
  • 30. Kontakt Mihovil Rister gsm +385 91 5865 907 Razvojni in転enjer, mail mihovil.rister@fiveminutes.eu Pet Minuta d.o.o. skype mihovil.rister web http://www.fiveminutes.eu