messaging over the web with websocket & jms · 2012-08-14 · websocket is two standards...
Post on 21-Jun-2020
36 Views
Preview:
TRANSCRIPT
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 1
High Performance
Creators of HTML5 WebSocket
Enterprise Support
WebSocket Gateway
Messaging over the Web with WebSocket & JMS
Robin Zimmermann Product Manager Kaazing
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 2
The Challenge
Unlock data from the enterprise
Message Broker / Bus
Database
Proprietary Server
Browser
Mobile
Tablet
Desktop
Enterprise
Web
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 3
Messaging Over the Web
Everybody wants it Enterprises have had it a long time
• But locked up in the enterprise
Web developers are new to it Many applications and open-source projects
do their own kind of pub-sub JMS is richer JMS is standard
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 4
Architecture
JMS Client
Web Trusted Network
Application Server / Container
Traditional application server or container approach
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 5
Architecture
JMS Client
Web Trusted Network
Application Server / Container
HTTP is half-duplex
JMS TCP
HTTP TCP
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 6
Architecture
JMS Client
Web Trusted Network
Application Server / Container
HTTP is half-duplex
JMS TCP
HTTP TCP
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 7
Architecture
It's all HTTP: SOAP REST JSP, ASP Servlets And so on...
JMS Client
Web Trusted Network
Application Server / Container
HTTP is half-duplex
JMS TCP
HTTP TCP
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 8
Limitations of HTTP
Designed for static document retrieval • HTML files, Images, CSS files, JavaScript files
Half-duplex • High latency
High Bandwidth • Headers • Cookies
Stateless
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 9
Workarounds for HTTP Limitations
Ajax Polling Long Polling Hanging GET Comet
Not true real time End users don't see the pain, but developers
and systems administrators do
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 10
Overhead
Example:
Type one character: ~1500 characters exchanged
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 11
HTTP Request Headers
GET /PollingStock//PollingStock HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/PollingStock/ Cookie: showInheritedConstant=false; showInheritedProtectedConstant=false; showInheritedProperty=false; showInheritedProtectedProperty=false; showInheritedMethod=false; showInheritedProtectedMethod=false; showInheritedEvent=false; showInheritedStyle=false; showInheritedEffect=false;
Client
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 12
HTTP Response Headers
Total overhead: 871 bytes (example) Often 1.5K+ bytes (for example, cookie data) Overhead is expensive
HTTP/1.x 200 OK X-Powered-By: Servlet/2.5 Server: Sun Java System Application Server 9.1_02 Content-Type: text/html;charset=UTF-8 Content-Length: 321 Date: Sat, 07 Nov 2009 00:32:46 GMT
Server
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 13
WebSocket
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 14
WebSocket is Two Standards
WebSocket Protocol Standards Body: IETF Status: RFC6455 HTML5 WebSocket API (or interface)
Standards Body: W3C Status: Draft
• Browser vendors • WebSocket server vendors
• Application developers
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 15
What is WebSocket?
Full-duplex TCP connection Low latency Low bandwidth
• Small number of fixed bytes per frame
Port 80/443 compatible Simple socket-like API
• Send messages • Event handler to receive messages
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 16
HTTP and WebSocket Work Together
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 17
HTTP and WebSocket Work Together
HTTP for static content
WebSocket for dynamic content
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 18
HTTP and WebSocket Work Together
WebSocket Gateway /
Server
Web Server / Cache Edge Network
HTTP HTTP
WebSocket
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 19
Architecture
JMS Client
Application Server / Container
Traditional application server or container approach
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 20
JMS Client
Architecture
JMS Client
Application Server / Container
Gateway architecture
WebSocket Gateway
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 21
JMS Client
Architecture
JMS Client
Application Server / Container
Not an application server or container
WebSocket Gateway
No code
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 22
Architecture
Client
Client
JMS
Application Server / Container
JMS JMS
HTTP
End-to-end protocol
WebSocket Gateway
JMS
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 23
Architecture
Client
Client
JMS TCP
Application Server / Container
JMS WS
JMS TCP
HTTP TCP
JMS
WebSocket Gateway
End-to-end protocol
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 24
Architecture
Client
Client Enterprise
Clients
JMS TCP
JMS TCP
Application Server / Container
JMS WS
JMS TCP
HTTP TCP
JMS
WebSocket Gateway
All clients are true JMS clients
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 25
Architecture
Client
Client Enterprise
Clients
JMS TCP
JMS TCP
Application Server / Container
JMS WS
JMS TCP
HTTP TCP
JMS
WebSocket Gateway
Clients are true JMS clients
createConnection(); session.createConsumer(); messageProducer.send();
createConnection(); session.createConsumer(); messageProducer.send();
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 26
Connectivity Logical versus physical connections
Web
FTP Server
Browser
FTP Client
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 27
Connectivity Logical versus physical connections
Web
FTP Server
Browser
FTP Client
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 28
Web
Connectivity Logical versus physical connections
Web
FTP Server
Browser
FTP Client
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 29
Architecture
Client
Client Enterprise
Clients
JMS
Application Server / Container
A Gateway architecture makes Web clients first-class citizens
JMS
WS
JMS
TCP
JMS
JMS HTTP
WebSocket Gateway
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 30
Architecture
Client
Client Enterprise
Clients
Application Server / Container
A Gateway architecture makes Web clients first-class citizens
JMS
JMS
JMS
JMS HTTP
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 31
Architecture
Client
Client Enterprise
Clients
JMS TCP
JMS TCP
Application Server / Container
HTTP TCP
JMS client library
JMS
JMS WS
JMS TCP WebSocket
Gateway
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 32
Architecture
Client
Client Enterprise
Clients
JMS TCP
JMS TCP
Application Server / Container
HTTP TCP
JMS client library
JMS
JMS WS
JMS TCP WebSocket
Gateway
• Standard JMS 1.1 API • Guaranteed, reliable delivery
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 33
Fan-out
Application Server/ Container
Publish once, deliver N times
WebSocket Gateway
JMS
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 34
Fan-out
Application Server/ Container
Increase clients to Web scale with no extra pressure on the back-end
WebSocket Gateway
JMS
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99
NAME AAPL
BUY 550.97
SELL 550.99 NAME AAPL
BUY 550.97
SELL 550.99 NAME AAPL
BUY 550.97
SELL 550.99 NAME AAPL
BUY 550.97
SELL 550.99 NAME AAPL
BUY 550.97
SELL 550.99
Pricing Engine
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 35
Application Logic
Client
Client
Application Server / Container
HTTP TCP
Back-end clients, systems, and services
JMS WS WebSocket
Gateway
Order System
Fulfillment
JMS
Trading Engine
CRM
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 36
Application Logic
Client
Client
Application Server / Container
HTTP TCP
Add services as required
JMS WS WebSocket
Gateway
Order System
Fulfillment
JMS
Trading Engine
Persistence
CRM
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 37
Application Logic
Client
Client
Application Server / Container
HTTP TCP
Add services as required
JMS WS WebSocket
Gateway
Order System
Fulfillment
CRM
JMS
Trading Engine
Application Logic
Persistence
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 38
Client-side
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 39
JavaScript Client
No plugin or installation Simply insert a script tag:
<script type="text/javascript" language="javascript" src="StompJms.js"></script>
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 40
Establish the Connection
ConnectionFactory cFactory = (ConnectionFactory) jmsContext.lookup("ConnectionFactory"); connection = cFactory.createConnection(username, password);
cFactory = new StompConnectionFactory(url); connectionFuture = cFactory.createConnection(username, password, connectionCallback); function connectionCallback() { connection = connectionFuture.getValue(); }
Java
JavaScript
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 41
Create the Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Java
JavaScript
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 42
Subscribe to a Topic
topic = session.createTopic("/topic/stock"); consumer = session.createConsumer(topic); consumer.setMessageListener(onMessage)
topic = session.createTopic("/topic/stock"); consumer = session.createConsumer(topic); consumer.setMessageListener(onMessage);
Java
JavaScript
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 43
Publish a Message
dest = session.createQueue(name); producer = session.createProducer(dest); textMsg = session.createTextMessage(message); message.setStringProperty(propName, propValue); producer.send(textMsg);
dest = session.createQueue(name); producer = session.createProducer(dest); textMsg = session.createTextMessage(message); message.setStringProperty(propName, propValue); producer.send(textMsg);
Java
JavaScript
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 44
Publish a Message
Optional callbacks for blocking calls:
dest = session.createQueue(name); producer = session.createProducer(dest); textMsg = session.createTextMessage(message); message.setStringProperty(propName, propValue); producer.send(textMsg);
dest = session.createQueue(name); producer = session.createProducer(dest); textMsg = session.createTextMessage(message); message.setStringProperty(propName, propValue); producer.send(textMsg, mySendCallback); function mySendCallback() { log("Message has been sent"); }
Java
JavaScript
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 45
Infrastructure & Security
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 46
Simplified Unified Architecture
Client
Client
Removes architecture in way
Application Server Farm
Proxy(s) Load Balancer(s)
Cluster
Trading Engine
News Feed
Payment System
Database Storage
Application Logic
Web Service
ERP/CRM System
JMS
WebSocket
WebSocket
SSL Termination
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 47
Simplified Unified Architecture
Client
Client
Lives in the DMZ. Connections fail fast. Single access point.
Application Server Farm
Cluster
Trading Engine
News Feed
Payment System
Database Storage
Application Logic
Web Service
ERP/CRM System
JMS
WebSocket
WebSocket
SSL Proxy LB
Trusted Network DMZ Web
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 48
Simplified Unified Architecture
Client
Client
Lives in the DMZ. Connections fail fast. Single access point.
Application Server Farm
Cluster
Trading Engine
News Feed
Payment System
Database Storage
Application Logic
Web Service
ERP/CRM System
JMS
WebSocket
WebSocket
SSL Proxy LB
• Security on the edge • Fail fast • Fine-grained authorization • Single Sign-On
Trusted Network DMZ Web
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 49
Key Takeaways
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 50
JMS Over the Web
Standard JMS 1.1 API JMS end-to-end Guaranteed message delivery JMS authentication and authorization Publish and subscribe to queues and topics Send and receive text and binary messages Multiple acknowledgement modes Priority, Expiration, and Delivery Mode support Client-initiated transactions Slow consumer message buffering Automatic reconnect for dropped connections
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 51
WebSocket
Full-duplex Low latency Low bandwidth Port 80/443 compatible Can transport higher-level protocols Enables New Architectures
• Not just for speeding up the client-server hop
Copyright © 2012 Kaazing Corporation. All Rights Reserved. 52
top related