Extending the                           Java Message Service                               to Web devices                 ...
Agenda    l    HTML5 WebSockets vs. HTTP    l    Java Message Service    l    Implementing JMS over WebSockets    l   ...
Networked Applications                                                        Full duplexTCP socket                    Thi...
Networked Applications                                                            Full duplexTCP socket                   ...
HTTP Workarounds & Hacks                                                                                 Full duplex      ...
HTML5 WebSocket l    Extends TCP across the web       l    Full-duplex, single socket, very low overhead       l    Sha...
HTTP vs. WebSocket                          HTTP                                      WebSocket Overhead                 1...
Overheard…     "Reducing kilobytes of data to 2 bytes… and     reducing latency from 150ms to 50ms is far more     than ma...
Using the WebSocket API     Java     //Create and connect new WebSocket     WebSocket mySocket = new WebSocket();     // A...
WebSocket Browser SupportBrowser native support      §    Chrome      §    Firefox (need to turn on)      §    Opera 10...
JMS Over WebSocket                                 WebSocket                     Browser                                  ...
JMS Over WebSocket                                 WebSocket                     Browser                                  ...
Java Message Service13   JavaOne 2011   © 2011 – Kaazing Corporation
Why JMS?  l    WebSocket is a good start but doesnt offer        much help to the application developer  l    JMS well e...
Why JMS over WebSocket?Typical Current JMS Architecture                        Firewall                                   ...
Why JMS over WebSocket?Typical Current JMS Architecture                        Firewall                                   ...
Implementing JMS over WebSockets17   JavaOne 2011   © 2011 – Kaazing Corporation
JMS over WebSocket  1. JMS Client library (in browser, web device)  2. Protocol  3. Server (bridge between broker & web)  ...
JMS Client Library ●    Implements the JMS objects and API      l    Initiate WebSocket connection      l    Encode outg...
The Protocol  l    STOMP        l      Text-based wire encoding, so suitable for multiple                client language...
JMS Client Library ●    session.createConsumer      l    → SUBSCRIBE destination:xxx      l    Await RECEIPT ●    produc...
JMS Client Library ●    Transactions      l    Group message sends and Acks      l    Single unit of work ●    Auto-reco...
The Server ●    Bridge between Web and Message Broker      l    Accepts WebSocket connections      l    Connects to JMS ...
The Server l    Simplest implementation:       l    Each client connection → 1 broker Connection and             Session...
Demos                                           http://portfolio.kaazing.me!http://forex.kaazing.me!25   JavaOne 2011     ...
Portfolio Demo ●    "stock" topic for stock price updates      l     MessageConsumer stockConsumer!      l     MessageLi...
Code Examples     l    Creating a connection (omitting exception handling)           env.put(Context.INITIAL_CONTEXT_FACT...
Code Examples     l    From there its all just standard JMS API           Session	  session	  =	  connection.createSessio...
A Real World Solution:     Kaazing WebSocket Gateway29    JavaOne 2011   © 2011 – Kaazing Corporation
WebSocket Client Support  l    Java and JavaFX  l    JavaScript  l    Microsoft Silverlight        and .NET  l    Adob...
WebSocket EmulationEmulation for browsers with no native WebSocket support:      l    Kaazing WebSocket Gateway: makes We...
Kaazing JMS Edition  l    Messages traverse firewalls and proxies  l    Fast, secure communication over the Internet  l...
Resource Offloading ●    Connection + Session offload (fan out)      l     Reduces broker resource usage      l     Mini...
Resource Offloading34   JavaOne 2011   © 2011 – Kaazing Corporation
JMS Gateway Features ●    “stomp.jms” service      l     Clients speak STOMP to the service.      l     Service uses ven...
Using Multiple Gateways ●    Hundreds of thousands of clients or more can be      supported by using a network of gateways...
Using Multiple Gateways37   JavaOne 2011   © 2011 – Kaazing Corporation
Writing Applications     l    JMS API is available to code running within the browser           or mobile device     l  ...
Live Customer Application39   JavaOne 2011   © 2011 – Kaazing Corporation
Take-aways     l    HTML5 WebSockets offers a paradigm shift for highly           interactive and scalable Web applicatio...
Conclusion“We’re committed to providing real-timeaccess to critical management informationacross the enterprise...Kaazing ...
Questions and Answers42   JavaOne 2011   © 2011 – Kaazing     Corporation
Upcoming SlideShare
Loading in …5
×

Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011

8,157 views

Published on

HTML5 WebSockets offers secure, high-performance, bidirectional network communication over the Web and in the cloud, making applications more responsive while using less bandwidth: live dashboards, financial quotes and transactions, real-time auctions and betting, gaming, equipment monitoring . . . the list is endless. In this session, see how to extend the Java Message Service (JMS) API to Web devices over HTML5 WebSockets to enrich and accelerate your applications. Discover through concrete code examples and a live customer application how to develop highly interactive UIs showing real-time data from any middleware supporting JMS, such as Tibco EMS or Informatica UMQ. Demos include JavaFX and JavaScript running in a Web browser and on a mobile device.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,157
On SlideShare
0
From Embeds
0
Number of Embeds
944
Actions
Shares
0
Downloads
152
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011

  1. 1. Extending the Java Message Service to Web devices over HTML5 WebSocketsChris Barrow, Peter MoskovitsKaazing CorporationJavaOne - October 5, 20111 JavaOne 2011 © 2011 – Kaazing Corporation
  2. 2. Agenda l  HTML5 WebSockets vs. HTTP l  Java Message Service l  Implementing JMS over WebSockets l  Demos and code examples l  Kaazing WebSocket Gateway, JMS Edition l  Questions2 JavaOne 2011 © 2011 – Kaazing Corporation
  3. 3. Networked Applications Full duplexTCP socket Thick Client Back-end server 3 JavaOne 2011 © 2011 – Kaazing Corporation
  4. 4. Networked Applications Full duplexTCP socket Thick Client Back-end server Full duplex Half DuplexHTTP Browser Middleware Back-end server 4 JavaOne 2011 © 2011 – Kaazing Corporation
  5. 5. HTTP Workarounds & Hacks Full duplex Half Duplex Browser Middleware Back-end server 5 JavaOne 2011 © 2011 – Kaazing Corporation
  6. 6. HTML5 WebSocket l  Extends TCP across the web l  Full-duplex, single socket, very low overhead l  Shares port with HTTP (80/443) Enables new classes of networked apps l  l  W3C API (JavaScript) l  IETF Protocol Full duplexWebSocket Browser Back-end server 6 JavaOne 2011 © 2011 – Kaazing Corporation
  7. 7. HTTP vs. WebSocket HTTP WebSocket Overhead 1000s of bytes (headers) 2-6 bytes/frame (typical) Latency New connection each time None: Reuses existing connection Latency (polling) Must wait for next request No waiting Latency (long polling) None, if server is holding No waiting a pending request (+ time to set up new connection) 7 JavaOne 2011 © 2011 – Kaazing Corporation
  8. 8. Overheard… "Reducing kilobytes of data to 2 bytes… and reducing latency from 150ms to 50ms is far more than marginal. In fact, these two factors alone are enough to make WebSocket seriously interesting to Google." Ian Hickson (Google, HTML5 Spec Lead) 8 JavaOne 2011 © 2011 – Kaazing Corporation
  9. 9. Using the WebSocket API Java //Create and connect new WebSocket WebSocket mySocket = new WebSocket(); // Associate listener webSocket.addWebSocketListener( new WebSocketListener() { @Override public void onMessage(WebSocketEvent event) { alert(event.getData()); } @Override public void onClose(WebSocketEvent closedEvent) {} }; mySocket.connect(new URI("ws://www.WebSocket.org")); mySocket.send("Hello world!"); 9 JavaOne 2011 © 2011 – Kaazing Corporation
  10. 10. WebSocket Browser SupportBrowser native support §  Chrome §  Firefox (need to turn on) §  Opera 10.7 (need to turn on) §  Safari §  Internet Explorer 9+ Beta 10 JavaOne 2011 © 2011 – Kaazing Corporation
  11. 11. JMS Over WebSocket WebSocket Browser Back-end server 11 JavaOne 2011 © 2011 – Kaazing Corporation
  12. 12. JMS Over WebSocket WebSocket Browser Back-end server JMS WebSocket Browser Back-end server 12 JavaOne 2011 © 2011 – Kaazing Corporation
  13. 13. Java Message Service13 JavaOne 2011 © 2011 – Kaazing Corporation
  14. 14. Why JMS? l  WebSocket is a good start but doesnt offer much help to the application developer l  JMS well established standard, widely available l  Offers important features over pure WebSocket: l  Publish and subscribe (Topics) for broadcast l  Point to point (Queues) for command processing l  Transactions l  Guaranteed delivery l  Structured data 14 JavaOne 2011 © 2011 – Kaazing Corporation
  15. 15. Why JMS over WebSocket?Typical Current JMS Architecture Firewall J2EE  Applica+on  Server   Web Container EJB Container SOAP over HTTP JMS Web Service EJB WEB JSP Message Broker HTTP (JMS Provider) 15 JavaOne 2011 © 2011 – Kaazing Corporation
  16. 16. Why JMS over WebSocket?Typical Current JMS Architecture Firewall J2EE  Applica+on  Server   Web Container EJB Container SOAP over HTTP JMS Web Service EJB WEB JSP Message Broker HTTP (JMS Provider)New WebSocket-based Architecture Firewall JMS Over WebSocket 16 JavaOne 2011 © 2011 – Kaazing Corporation
  17. 17. Implementing JMS over WebSockets17 JavaOne 2011 © 2011 – Kaazing Corporation
  18. 18. JMS over WebSocket 1. JMS Client library (in browser, web device) 2. Protocol 3. Server (bridge between broker & web) 4. Message Broker (JMS Provider) 18 JavaOne 2011 © 2011 – Kaazing Corporation
  19. 19. JMS Client Library ●  Implements the JMS objects and API l  Initiate WebSocket connection l  Encode outgoing JMS messages in STOMP l  Decode and deliver incoming messages ●  Manage connections and sessions, stop and start, message listeners, reconnect ●  A single WebSocket connection suffices (full duplex, asynchronous receive) 19 JavaOne 2011 © 2011 – Kaazing Corporation
  20. 20. The Protocol l  STOMP l  Text-based wire encoding, so suitable for multiple client languages (Java, JavaScript, ...) l  http://stomp.codehaus.org & http://stomp.github.com! l  Wireline encoding into STOMP: l  CONNECTnNAME:namen PASS:password (once) l  Encode JMS properties as key-value pairs: SENDnprop1:valuenprop2 -  -  MESSAGEnprop1:valuenprop2 l  SUBSCRIBEndestination:/topic/stock l  BEGIN, COMMIT, ABORT 20 JavaOne 2011 © 2011 – Kaazing Corporation
  21. 21. JMS Client Library ●  session.createConsumer l  → SUBSCRIBE destination:xxx l  Await RECEIPT ●  producer.send l  → SEND prop1:val1... <text> l  Await RECEIPT ●  Separate thread(s): read MESSAGEs l  Route to appropriate MessageListener l  Send ACK 21 JavaOne 2011 © 2011 – Kaazing Corporation
  22. 22. JMS Client Library ●  Transactions l  Group message sends and Acks l  Single unit of work ●  Auto-reconnect l  For resilience to network failures l  Reissue SUBSCRIBEs ●  Other client languages: l  Javascript, Flash, .Net 22 JavaOne 2011 © 2011 – Kaazing Corporation
  23. 23. The Server ●  Bridge between Web and Message Broker l  Accepts WebSocket connections l  Connects to JMS provider ●  Converts incoming STOMP frames to JMS API calls ●  Routes messages from provider back to clients ●  Must manage flow control 23 JavaOne 2011 © 2011 – Kaazing Corporation
  24. 24. The Server l  Simplest implementation: l  Each client connection → 1 broker Connection and Session l  Each client subscription (message consumer) → 1 consumer in broker l  More scalable: l  1 connection for many clients l  Single topic subscription for many clients 24 JavaOne 2011 © 2011 – Kaazing Corporation
  25. 25. Demos http://portfolio.kaazing.me!http://forex.kaazing.me!25 JavaOne 2011 © 2011 – Kaazing Corporation
  26. 26. Portfolio Demo ●  "stock" topic for stock price updates l  MessageConsumer stockConsumer! l  MessageListener: portfolioModel.updateStock()! ●  Temporary queue for command responses l  responseQueue = session.createTemporaryQueue()! ●  "command" queue to send commands l  producer.send (replyTo=responseQueue) l  command property (get_portfolio, get_balance, buy, sell)26 JavaOne 2011 © 2011 – Kaazing Corporation
  27. 27. Code Examples l  Creating a connection (omitting exception handling) env.put(Context.INITIAL_CONTEXT_FACTORY,                      StompInitialContextFactory.class.getName());   env.put(Context.PROVIDER_URL,  “ws://myhost:80/stomp.jms”);   InitialContext  ctx  =  new  InitialContext(env);   ConnectionFactory  cf  =                        (ConnectionFactory)ctx.lookup(“ConnectionFactory”);   Connection  connection  =  cf.createConnection();   l  Destination look up Topic  stockTopic  =  (Topic)ctx.lookup(“/topic/stock”);27 JavaOne 2011 © 2011 – Kaazing Corporation
  28. 28. Code Examples l  From there its all just standard JMS API Session  session  =  connection.createSession(false,                                                  Session.AUTO_ACKNOWLEDGE);   MessageConsumer  stockConsumer  =                    session.createConsumer(stockTopic);     //  Listen  for  stock  price  changes   stockConsumer.setMessageListener(new  MessageListener()  {          @Override          public  void  onMessage(Message  message)  {                  try  {                          String  stockData  =  ((TextMessage)message).getText();                          portfolioModel.updateStock(new  Stock(stockData));                  }                  catch(JMSException  e)  {                  }          }   }   connection.start();  28 JavaOne 2011 © 2011 – Kaazing Corporation
  29. 29. A Real World Solution: Kaazing WebSocket Gateway29 JavaOne 2011 © 2011 – Kaazing Corporation
  30. 30. WebSocket Client Support l  Java and JavaFX l  JavaScript l  Microsoft Silverlight and .NET l  Adobe Flex (Flash) 30 JavaOne 2011 © 2011 – Kaazing Corporation
  31. 31. WebSocket EmulationEmulation for browsers with no native WebSocket support: l  Kaazing WebSocket Gateway: makes WebSocket work in all browsers today: l  Internet Explorer 6, 7, 8 l  Firefox 3.6 l  And more . . . 31 JavaOne 2011 © 2011 – Kaazing Corporation
  32. 32. Kaazing JMS Edition l  Messages traverse firewalls and proxies l  Fast, secure communication over the Internet l  Message distribution to massive numbers of clients thanks to resource offloading (fan-out) 32 JavaOne 2011 © 2011 – Kaazing Corporation
  33. 33. Resource Offloading ●  Connection + Session offload (fan out) l  Reduces broker resource usage l  Minimal connections, sessions to broker ●  Java NIO (Apache Mina framework) ●  Subscription offload l  Multiplexed over shared connection, single message consumer l  Gateway tracks subscribed topics and queues from all connected clients l  Gateway handles individual client acknowledgments33 JavaOne 2011 © 2011 – Kaazing Corporation
  34. 34. Resource Offloading34 JavaOne 2011 © 2011 – Kaazing Corporation
  35. 35. JMS Gateway Features ●  “stomp.jms” service l  Clients speak STOMP to the service. l  Service uses vendors JMS API to talk to broker l  Connection, session and subscription offload ●  “stomp.proxy” service l  Clients speak STOMP to the service l  Service uses STOMP to talk to “stomp.jms” service running on another Gateway l  Further offload ●  Gateway clusters for High Availability35 JavaOne 2011 © 2011 – Kaazing Corporation
  36. 36. Using Multiple Gateways ●  Hundreds of thousands of clients or more can be supported by using a network of gateways ●  “stomp.proxy” gateways at the edge (near users) l  Route messages to central gateway running “stomp.jms” service l  Connection offloading (single connection to central gateway) ●  Most network traffic is local ●  Use gateway clusters for HA36 JavaOne 2011 © 2011 – Kaazing Corporation
  37. 37. Using Multiple Gateways37 JavaOne 2011 © 2011 – Kaazing Corporation
  38. 38. Writing Applications l  JMS API is available to code running within the browser or mobile device l  Gateway provides client libraries l  Written like a Java JMS client l  Similar concepts and APIs for each client technology (JavaScript, Flash, .Net) l  Application needs to include Kaazing JMS library files (jars, .js)38 JavaOne 2011 © 2011 – Kaazing Corporation
  39. 39. Live Customer Application39 JavaOne 2011 © 2011 – Kaazing Corporation
  40. 40. Take-aways l  HTML5 WebSockets offers a paradigm shift for highly interactive and scalable Web applications l  High level protocols can be extended beyond the firewall all the way to Web devices: l  JMS l  XMPP l  AMQP l  Production solution with live customers available today40 JavaOne 2011 © 2011 – Kaazing Corporation
  41. 41. Conclusion“We’re committed to providing real-timeaccess to critical management informationacross the enterprise...Kaazing solves the industry’s fundamental issueswhich have kept yesterday’s web architecturefrom meeting these needs.” Quintin Gomez, CTO of ITRS Group, 28 Sep 1141 JavaOne 2011 © 2011 – Kaazing Corporation
  42. 42. Questions and Answers42 JavaOne 2011 © 2011 – Kaazing Corporation

×