Download presentation
Presentation is loading. Please wait.
Published byStella Harper Modified over 9 years ago
1
Message Framework Topic subscribe for javascript/flex client
2
Requirements Topic, message management Publish topic messages to javascript client Publish topic messages to flex client Subscribe topic by javascript client Subscribe topic by flex client
3
System Topology JavaScript Client Flex Client Domain A Rest Framework Message Framework Other Component Topic Manager dwr Flex data service subscribe publish subscribe
4
TopicManager Rest framework or other components can send topic messages by TopicManager API: protected void notifyJSClient(String topic, List messages) Send messages to javascript client Send messages to flex client
5
Send message to javascript DWR http://directwebremoting.org/dwr/index.html http://directwebremoting.org/dwr/index.html DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible. DWR Reverse Ajax, it gives us the ability to asynchronously send data from a web-server to a browser. DWR Reverse Ajax supports 3 methods of pushing the data from to the browser: Piggyback, Polling and Comet. More detail refer to http://directwebremoting.org/dwr/documentation/reverse-ajax/index.html http://directwebremoting.org/dwr/documentation/reverse-ajax/index.html
6
Send message to javascript Using dwr to manager the topics, messages and clients Public api in TopicManager: protected void notifyJSClient(String topic, List messages) Dwr configuration, refer to web.xml: dwr-invoker DWR Servlet Direct Web Remoter Servlet com.vitria.dwr.servlet.OSGiDwrServlet …… org.directwebremoting.extend.Compressor org.directwebremoting.impl.LegacyCompressor
7
activeReverseAjaxEnabled true <!-- This enables full streaming mode. If set to -1, it will using full streaming model totally. If it is set to <500, client will restart a new connection without wait after write which is the same with set to 0. It's probably better to leave this out if you are running across the internet. --> maxWaitAfterWrite 5000 <!-- This enables polling streaming mode, set the wait time before next polling. For polling model only. For "Early Closing Mode", it will compute the disconnectedTime dynamically according the server load--> disconnectedTime 5000 url:/call/plainpoll/ com.vitria.dwr.reverse.TopicPollHandler ……
8
Send messages to flex client Using flex BlazeDS to implement Public api in TopicManager: protected void notifyASClient(String topic, List messages) BlazeDS configuration, refer to messaging-config.xml: 0 1000 0 false
9
Javascript client Based on DWR Reverse Ajax APIs, refer to engine.js New APIs for subscribe topics, refer to reverse.js: /** * Register the callback on one topic and the reverse ajax will be started when register. * @param topic_id, the topic id to subscribe. * @param callback, the listener on the topic, should accept one parameter just like {"topic": "topic_id", "messages": ["message1", "message2"]}. **/ dwr.reverse.register = function(topic_id, callback) { } /** * Unregister the callback on one topic. * @param topic_id, the topic id to unsubscribe. * @param callback, the listener on the topic; if null, the whole topic will unsubscribe. **/ dwr.reverse.unregister = function(topic_id, callback) { }
10
Flex client Based on Flex Messaging APIs New APIs for subscribe topics, refer to RestMessageManager.as: /** * Register the callback on one topic. * @param topic_id, the topic id to subscribe. * @param callback, the listener on the topic, should accept one parameter of TopicMessage instance. **/ public function register(topic:String, callback:Function):void { } /** * Unregister the callback on one topic. * @param topic_id, the topic id to unsubscribe. * @param callback, the listener on the topic; if null, the whole topic will unsubscribe. **/ public function unregister(topic:String, callback:Function):void { }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.