SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
REACTIVE
Message Driven
Responsive
REACTIVEPROGRAMMING
Message Driven
Responsive
REACTIVESYSTEM
Message Driven
Responsive
Resilient
Elastic
WHY REACTIVE SYSTEMS?
TYPICAL JAVA APP...
final String PID = ManagementFactory.getRuntimeMXBean().getName();
@RequestMapping(value = "/work", method = RequestMethod.GET)
public @ResponseBody String work(HttpServletResponse resp) {
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
return "Pi is: " + Pi.calculate(100_000_000);
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public @ResponseBody String home(HttpServletResponse resp) {
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
return "Current PID: " + PID;
}
TYPICAL NODE APP...
var process = require('process');
var app = require('express')();
var pi = require('./pi');
app.get('/', function (req, res) {
res.send('Request served by ' + process.pid);
});
app.get('/work', function (req, res) {
res.send('Pi = (' + process.pid + ') ' + pi(100000000));
});
app.listen(8080, function () {
console.log('Pi server listening on port 8080!')
});
DEMO
TYPICAL VERT.X APP...
// Initial Setup //
final String PID = ManagementFactory
.getRuntimeMXBean().getName();
final Router app = Router.router(vertx);
// Reactive Trait: RESPONSIVE //
// responsive, even under high load this handler
// can respond to requests
app.get("/").handler(ctx -> {
ctx.response()
.putHeader("content-type", "text/plain")
// Reactive Trait: RESILIENT //
// resilient, in case of failure the system
// recovers
.end("Current PID: " + PID);
});
// Reactive Trait: MESSAGE DRIVEN //
app.get("/work").handler(ctx -> {
// message driven, events can cross boundaries
// using a message driven architecture
vertx.eventBus().send("pi", null, reply -> {
if (reply.failed()) {
ctx.fail(reply.cause());
} else {
ctx.response()
.putHeader("content-type", "text/plain")
.end("Pi = " + reply.result().body());
}
});
});
// Reactive Trait: ELASTIC //
// elastic we can deploy several consumers to
// scale the application
vertx.eventBus().consumer("pi", m -> {
// can mix blocking and non-blocking code
vertx.executeBlocking(
fut -> fut.complete(Pi.calculate(100000000)),
false,
fut -> m.reply(PID + ": " + fut.result()));
});
DEMO
REACTIVE APPLICATIONS
REACT.JS
Simplicity
Component Based Approach
Performance and Virtual DOM
Awesome for SEO
Testability/Developers tools
Bonus: Mobile apps with react native
REACT.JS
Simplicity
Component Based Approach
Performance and Virtual DOM
Awesome for SEO
Testability/Developers tools
Bonus: Mobile apps with react native
WITH VERT.X YOU CAN...
Run JS with your Java,Scala,Kotlin,Groovy,Ruby,etc...
Mix CPU intensive tasks with non CPU intensive
Call EventBus remote services as if they were local
drop Node.JS
VERT.X UNIVERSAL APP
// Initial Setup //
const Router = require("vertx-web-js/router")
const StaticHandler =
require("vertx-web-js/static_handler")
import React from 'react'
import {renderToString} from 'react-dom/server'
import {match, RouterContext} from 'react-router'
import routes from '../shared/components/routes'
const app = Router.router(vertx)
// Rest API (Similar to Express.JS) //
app.get('/api/post').handler((ctx) => {
ctx.response()
.putHeader("content-type", "application/json")
.end(JSON.stringify(posts))
})
app.get('/api/post/:id').handler((ctx) => {
const id = ctx.request().getParam('id')
const post = posts.filter(p => p.id == id)
if (post) {
ctx.response()
.putHeader(
"content-type", "application/json")
.end(JSON.stringify(post[0]))
} else {
ctx.fail(404)
}
})
// Mix React.JS with Vert.x //
app.get().handler((ctx) => {
match({
routes: routes,
location: ctx.request().uri()
}, (err, redirect, props) => {
if (err) {
ctx.fail(err.message);
} else if (redirect) {
ctx.response()
.putHeader("Location",
redirect.pathname + redirect.search)
.setStatusCode(302)
.end();
} else if (props) {
const routerContextWithData = (
<RouterContext
{...props}
createElement={(Component, props) => {
return <Component
posts={posts} {...props} />
}}
/>)
VERT.X UNIVERSAL APP
// Mix React.JS with Vert.x //
app.get().handler((ctx) => {
match({
routes: routes,
location: ctx.request().uri()
}, (err, redirect, props) => {
if (err) {
ctx.fail(err.message);
} else if (redirect) {
ctx.response()
.putHeader("Location",
redirect.pathname + redirect.search)
.setStatusCode(302)
.end();
} else if (props) {
const routerContextWithData = (
<RouterContext
{...props}
createElement={(Component, props) => {
return <Component
posts={posts} {...props} />
}}
/>)
// Render React.js without Node //
const appHtml =
renderToString(routerContextWithData)
ctx.response()
.putHeader("content-type", "text/html")
.end(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Universal Blog</title>
</head>
<body>
<div id="app">${appHtml}</div>
<script
src="/bundle.js"></script>
</body>
</html>`)
} else {
ctx.next()
}
})
})
// Serve resources and start //
app.get().handler(StaticHandler.create().handle)
vertx.createHttpServer()
.requestHandler(app.accept).listen(8080)
DEMO
WHAT ABOUT MICROSERVICES?
IN YOUR VERT.X APP...
final Router router = Router.router(vertx);
// Allow events for the designated addresses
BridgeOptions sockjsConfig = new BridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("greetings"))
.addOutboundPermitted(new PermittedOptions().setAddress("greetings"));
// Create the event bus bridge and add it to the router.
router
.route("/eventbus/*")
.handler(SockJSHandler.create(vertx).bridge(sockjsConfig));
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
IN YOUR VERT.X APP (2)...
...
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
EventBus eb = vertx.eventBus();
vertx.setPeriodic(500, t ->
eb.send("greetings",
new JsonObject().put("msg", "Greetings from Vert.x!")));
IN YOUR REACT APP...
import EventBus from 'vertx3-eventbus-client'
const eb = new EventBus(`//${window.location.host}/eventbus`)
class App extends React.Component {
constructor(props) {
super(props)
this.state = { messages: [] }
}
render() {
let listItems = this.state.messages.map(message => {
return ( <li>{ `${message}` }</li> )
})
return ( <div><ul>{listItems}</ul></div> )
}
IN YOUR REACT APP (2)...
...
class App extends React.Component {
...
componentWillMount() {
Rx.Observable
.create((observer) => {
eb.registerHandler('greetings', (err, msg) => {
observer.next(msg.body.msg);
});
})
.subscribe(message => {
this.state.messages.unshift(message);
this.setState({ messages: this.state.messages });
});
}
IN YOUR NODE APP...
var EventBus = require('vertx3-eventbus-client');
var eb = new EventBus('http://localhost:8080/eventbus');
eb.onerror = function (err) {
console.error(err);
};
eb.onopen = function () {
setInterval(function () {
eb.send('greetings', {msg: 'Hello from Node.js!'});
}, 500);
};
IN YOUR REACT APP (3)...
...
class App extends React.Component {
...
static sayHello(e) {
e.preventDefault();
eb.send('greetings', {msg: 'Hello from React.js!'})
}
render() {
return (
...
<button onClick={App.sayHello}>Say Hello!</button>
DEMO
YOU GET A THE FREE BOOK!
WHAT ABOUT CALLBACK HELL?
ASYNC CODE:
route().handler(ctx -> {
ctx.user().isAuthorized("READ", res -> {
db.getConnection(conn -> {
conn.query("select * from test", rs -> {
conn.close( v -> {
ctx.response.end(rs.encode());
});
});
});
});
});
RX TO THE RESCUE
route().handler(ctx -> {
ctx.user().rxIsAuthorized("READ")
.flatMap(r -> db.rxGetConnection(conn))
.flatMap(c -> c.rxQuery("select * from test"))
.doAfterTerminate(c::close)
.subscribe(rs -> ctx.response.end(rs.encode()));
});
OR WITH (JS) VERT.X APP...
route().handler(async (ctx) -> {
if (await ctx.user().isAuthorized("READ")) {
try {
let c = await db.getConnection()
let rs = await c.query("select * from test")
ctx.response.end(rs.encode())
} finally {
c.close()
}
}
});
OR WITH (VERT.X SYNC) VERT.X APP...
route().handler(fiberHandler(ctx -> {
if (awaitResult(h -> ctx.user().isAuthorized("READ", h))) {
try (SQLConnection conn = awaitResult(jdbc::getConnection)) {
ResultSet res =
awaitResult(h -> conn.query("select * from test", h));
ctx.response.end(rs.encode());
}
}
}));
REACTIVE ISFUN!
HOW DO I START?
Github
Twitter
Youtube
Book
http://vertx.io
https://groups.google.com/forum/#!forum/vertx
https://github.com/vert-x3
@vertx_project
https://www.youtube.com/vertx_project
https://t.co/m2w7puPba8
THE END
Thanks you!
Follow me on twitter
Visit my blog
Start your project
@jetdrone
http://jetdrone.xyz
http://jetdrone.xyz/vertx-starter

Mais conteúdo relacionado

Mais procurados

"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "FDConf
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with ReduxFernando Daciuk
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON APIShengyou Fan
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代Shengyou Fan
 
Redux training
Redux trainingRedux training
Redux trainingdasersoft
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJSAll Things Open
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
State Models for React with Redux
State Models for React with ReduxState Models for React with Redux
State Models for React with ReduxStephan Schmidt
 
How to connect AngularJS to servers
How to connect AngularJS to serversHow to connect AngularJS to servers
How to connect AngularJS to serversCarlos Morales
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 

Mais procurados (20)

"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
 
Redux training
Redux trainingRedux training
Redux training
 
Retrofit
RetrofitRetrofit
Retrofit
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
Redux Universal
Redux UniversalRedux Universal
Redux Universal
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
State Models for React with Redux
State Models for React with ReduxState Models for React with Redux
State Models for React with Redux
 
React redux
React reduxReact redux
React redux
 
React и redux
React и reduxReact и redux
React и redux
 
React, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
 
React & redux
React & reduxReact & redux
React & redux
 
How to connect AngularJS to servers
How to connect AngularJS to serversHow to connect AngularJS to servers
How to connect AngularJS to servers
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 

Semelhante a Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017

Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Codemotion
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stackTomáš Kypta
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Morris Singer
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09Daniel Bryant
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019DevClub_lv
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creatorsGeorge Bukhanov
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascriptEldar Djafarov
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
 

Semelhante a Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017 (20)

React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stack
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
 
React 101
React 101React 101
React 101
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
React lecture
React lectureReact lecture
React lecture
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
 
mobl
moblmobl
mobl
 
Reduxing like a pro
Reduxing like a proReduxing like a pro
Reduxing like a pro
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 

Mais de Codemotion

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Codemotion
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyCodemotion
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaCodemotion
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserCodemotion
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Codemotion
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
 

Mais de Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017

  • 1.
  • 3.
  • 6.
  • 8. TYPICAL JAVA APP... final String PID = ManagementFactory.getRuntimeMXBean().getName(); @RequestMapping(value = "/work", method = RequestMethod.GET) public @ResponseBody String work(HttpServletResponse resp) { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); return "Pi is: " + Pi.calculate(100_000_000); } @RequestMapping(value = "/", method = RequestMethod.GET) public @ResponseBody String home(HttpServletResponse resp) { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); return "Current PID: " + PID; }
  • 9. TYPICAL NODE APP... var process = require('process'); var app = require('express')(); var pi = require('./pi'); app.get('/', function (req, res) { res.send('Request served by ' + process.pid); }); app.get('/work', function (req, res) { res.send('Pi = (' + process.pid + ') ' + pi(100000000)); }); app.listen(8080, function () { console.log('Pi server listening on port 8080!') });
  • 10.
  • 11. DEMO
  • 12. TYPICAL VERT.X APP... // Initial Setup // final String PID = ManagementFactory .getRuntimeMXBean().getName(); final Router app = Router.router(vertx); // Reactive Trait: RESPONSIVE // // responsive, even under high load this handler // can respond to requests app.get("/").handler(ctx -> { ctx.response() .putHeader("content-type", "text/plain") // Reactive Trait: RESILIENT // // resilient, in case of failure the system // recovers .end("Current PID: " + PID); }); // Reactive Trait: MESSAGE DRIVEN // app.get("/work").handler(ctx -> { // message driven, events can cross boundaries // using a message driven architecture vertx.eventBus().send("pi", null, reply -> { if (reply.failed()) { ctx.fail(reply.cause()); } else { ctx.response() .putHeader("content-type", "text/plain") .end("Pi = " + reply.result().body()); } }); }); // Reactive Trait: ELASTIC // // elastic we can deploy several consumers to // scale the application vertx.eventBus().consumer("pi", m -> { // can mix blocking and non-blocking code vertx.executeBlocking( fut -> fut.complete(Pi.calculate(100000000)), false, fut -> m.reply(PID + ": " + fut.result())); });
  • 13. DEMO
  • 15. REACT.JS Simplicity Component Based Approach Performance and Virtual DOM Awesome for SEO Testability/Developers tools Bonus: Mobile apps with react native
  • 16. REACT.JS Simplicity Component Based Approach Performance and Virtual DOM Awesome for SEO Testability/Developers tools Bonus: Mobile apps with react native
  • 17.
  • 18. WITH VERT.X YOU CAN... Run JS with your Java,Scala,Kotlin,Groovy,Ruby,etc... Mix CPU intensive tasks with non CPU intensive Call EventBus remote services as if they were local drop Node.JS
  • 19. VERT.X UNIVERSAL APP // Initial Setup // const Router = require("vertx-web-js/router") const StaticHandler = require("vertx-web-js/static_handler") import React from 'react' import {renderToString} from 'react-dom/server' import {match, RouterContext} from 'react-router' import routes from '../shared/components/routes' const app = Router.router(vertx) // Rest API (Similar to Express.JS) // app.get('/api/post').handler((ctx) => { ctx.response() .putHeader("content-type", "application/json") .end(JSON.stringify(posts)) }) app.get('/api/post/:id').handler((ctx) => { const id = ctx.request().getParam('id') const post = posts.filter(p => p.id == id) if (post) { ctx.response() .putHeader( "content-type", "application/json") .end(JSON.stringify(post[0])) } else { ctx.fail(404) } }) // Mix React.JS with Vert.x // app.get().handler((ctx) => { match({ routes: routes, location: ctx.request().uri() }, (err, redirect, props) => { if (err) { ctx.fail(err.message); } else if (redirect) { ctx.response() .putHeader("Location", redirect.pathname + redirect.search) .setStatusCode(302) .end(); } else if (props) { const routerContextWithData = ( <RouterContext {...props} createElement={(Component, props) => { return <Component posts={posts} {...props} /> }} />)
  • 20. VERT.X UNIVERSAL APP // Mix React.JS with Vert.x // app.get().handler((ctx) => { match({ routes: routes, location: ctx.request().uri() }, (err, redirect, props) => { if (err) { ctx.fail(err.message); } else if (redirect) { ctx.response() .putHeader("Location", redirect.pathname + redirect.search) .setStatusCode(302) .end(); } else if (props) { const routerContextWithData = ( <RouterContext {...props} createElement={(Component, props) => { return <Component posts={posts} {...props} /> }} />) // Render React.js without Node // const appHtml = renderToString(routerContextWithData) ctx.response() .putHeader("content-type", "text/html") .end(`<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Universal Blog</title> </head> <body> <div id="app">${appHtml}</div> <script src="/bundle.js"></script> </body> </html>`) } else { ctx.next() } }) }) // Serve resources and start // app.get().handler(StaticHandler.create().handle) vertx.createHttpServer() .requestHandler(app.accept).listen(8080)
  • 21. DEMO
  • 22.
  • 24. IN YOUR VERT.X APP... final Router router = Router.router(vertx); // Allow events for the designated addresses BridgeOptions sockjsConfig = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("greetings")) .addOutboundPermitted(new PermittedOptions().setAddress("greetings")); // Create the event bus bridge and add it to the router. router .route("/eventbus/*") .handler(SockJSHandler.create(vertx).bridge(sockjsConfig)); router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router::accept).listen(8080);
  • 25. IN YOUR VERT.X APP (2)... ... router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router::accept).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(500, t -> eb.send("greetings", new JsonObject().put("msg", "Greetings from Vert.x!")));
  • 26. IN YOUR REACT APP... import EventBus from 'vertx3-eventbus-client' const eb = new EventBus(`//${window.location.host}/eventbus`) class App extends React.Component { constructor(props) { super(props) this.state = { messages: [] } } render() { let listItems = this.state.messages.map(message => { return ( <li>{ `${message}` }</li> ) }) return ( <div><ul>{listItems}</ul></div> ) }
  • 27. IN YOUR REACT APP (2)... ... class App extends React.Component { ... componentWillMount() { Rx.Observable .create((observer) => { eb.registerHandler('greetings', (err, msg) => { observer.next(msg.body.msg); }); }) .subscribe(message => { this.state.messages.unshift(message); this.setState({ messages: this.state.messages }); }); }
  • 28. IN YOUR NODE APP... var EventBus = require('vertx3-eventbus-client'); var eb = new EventBus('http://localhost:8080/eventbus'); eb.onerror = function (err) { console.error(err); }; eb.onopen = function () { setInterval(function () { eb.send('greetings', {msg: 'Hello from Node.js!'}); }, 500); };
  • 29. IN YOUR REACT APP (3)... ... class App extends React.Component { ... static sayHello(e) { e.preventDefault(); eb.send('greetings', {msg: 'Hello from React.js!'}) } render() { return ( ... <button onClick={App.sayHello}>Say Hello!</button>
  • 30. DEMO
  • 31. YOU GET A THE FREE BOOK!
  • 33. ASYNC CODE: route().handler(ctx -> { ctx.user().isAuthorized("READ", res -> { db.getConnection(conn -> { conn.query("select * from test", rs -> { conn.close( v -> { ctx.response.end(rs.encode()); }); }); }); }); });
  • 34. RX TO THE RESCUE route().handler(ctx -> { ctx.user().rxIsAuthorized("READ") .flatMap(r -> db.rxGetConnection(conn)) .flatMap(c -> c.rxQuery("select * from test")) .doAfterTerminate(c::close) .subscribe(rs -> ctx.response.end(rs.encode())); });
  • 35. OR WITH (JS) VERT.X APP... route().handler(async (ctx) -> { if (await ctx.user().isAuthorized("READ")) { try { let c = await db.getConnection() let rs = await c.query("select * from test") ctx.response.end(rs.encode()) } finally { c.close() } } });
  • 36. OR WITH (VERT.X SYNC) VERT.X APP... route().handler(fiberHandler(ctx -> { if (awaitResult(h -> ctx.user().isAuthorized("READ", h))) { try (SQLConnection conn = awaitResult(jdbc::getConnection)) { ResultSet res = awaitResult(h -> conn.query("select * from test", h)); ctx.response.end(rs.encode()); } } }));
  • 38. HOW DO I START? Github Twitter Youtube Book http://vertx.io https://groups.google.com/forum/#!forum/vertx https://github.com/vert-x3 @vertx_project https://www.youtube.com/vertx_project https://t.co/m2w7puPba8
  • 39. THE END Thanks you! Follow me on twitter Visit my blog Start your project @jetdrone http://jetdrone.xyz http://jetdrone.xyz/vertx-starter