real time com java e node.js
TRANSCRIPT
![Page 1: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/1.jpg)
Real Time com Java e Node.Js
Fabiano Guizellini Modos
![Page 2: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/2.jpg)
Agenda
1. Node.js
2. Socket.io
2.1 Websockets
3. Redis
4. Jedis
![Page 3: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/3.jpg)
![Page 4: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/4.jpg)
Por que Node.Js?
“I am not happy with the way web
servers and apps work today”
“We need something faster, highly
scalable”
Ryan Dahl (Criador do Node.Js)
![Page 5: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/5.jpg)
O que é Node.Js?Servidor web em JavaScript
![Page 6: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/6.jpg)
Node.Js
• Biblioteca de alta performance para operações
I/O (Ex: HTTP)
• Asyncronous, non-blocking I/O
• Single threaded, event loop
• Leve, eficiente e rápido
• Modular, possui gerenciador de pacotes: npm
“Node.js is a platform built on Chrome’s JavaScript
runtime for easily building fast, scalable network
applications. “ http://nodejs.org
![Page 7: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/7.jpg)
Node.Js – Event Loop
http://magnetik.github.io/node-webid-report/
![Page 8: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/8.jpg)
Node.js
Browser
R
E
Q
R
E
Q
R
E
S
P
![Page 9: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/9.jpg)
![Page 10: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/10.jpg)
Por quê Socket.io?
• Você já precisou enviar informação para o
browser em real time?
• Você já desenvolveu sua própria tecnologia de
push?
![Page 11: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/11.jpg)
Socket.IO
• 100% JavaScript
• Websockets
• Fallback transports-flash sockets-ajax long polling-ajax streaming-iframe-json polling
“Socket.IO aims to make realtime apps
possible in every browser and mobile device…”
http://socket.io
![Page 12: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/12.jpg)
Websockets
• Protocolo padronizado pelo IETF, RFC 6455
• Conexão Bi-direcional, full duplex... TCP socket
• HTTP handshake somente uma vez
• 2 bytes overhead
![Page 13: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/13.jpg)
Node.js
Socket.io
W
S
Browser
Socket.io
![Page 14: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/14.jpg)
![Page 15: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/15.jpg)
Por quê Redis?
• Você já precisou de um BD em memória?
• Você já precisou compartilhar informação
entre aplicações em real time?
![Page 16: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/16.jpg)
Redis
• Key-value datastore, em memória
• Publish/Subscriber channels
• Master-slave replication, non blocking
• Etc...
“It is often referred to as a data structure
server since keys can contain strings, hashes,
lists, sets and sorted sets.” http://redis.io
![Page 17: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/17.jpg)
Node.js
Socket.io
S
U
B
Redis
P
U
B
W
S
Browser
Socket.io
![Page 18: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/18.jpg)
JEDIS
• Connection handling
• Commands operating on strings, hashes, lists,
sets, sorted lists
• Publish/Subscribe
• Etc...
“Jedis is a blazingly small and sane Redis java
client.” https://github.com/xetorthio/jedis
![Page 19: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/19.jpg)
Node.js
Socket.io
S
U
B
Browser
Cliente Java Redis
Jedis
PUBLISHPUBLISH
P
U
B
W
S
Socket.io
SUBSCRIBESUBSCRIBE
![Page 20: Real time com java e Node.Js](https://reader034.vdocument.in/reader034/viewer/2022042723/587e8b611a28ab672b8b4a73/html5/thumbnails/20.jpg)