| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Adobe BlazeDS
Revision: 2991
Author: matamel@adobe.com
Date: 25 Aug 2008 17:00:50
Changes:Add a MultiTopicConsumer sample to team app for testing.
Files:| ... | ...@@ -153,6 +153,16 @@ | |
| 153 | 153 | </server> |
| 154 | 154 | </properties> |
| 155 | 155 | </destination> |
| 156 | ||
| 157 | <destination id="messaging_AMF_Stream_Subtopic" channels="my-amf-stream"> | |
| 158 | <properties> | |
| 159 | <server> | |
| 160 | <allow-subtopics>true</allow-subtopics> | |
| 161 | <subtopic-separator>.</subtopic-separator> | |
| 162 | </server> | |
| 163 | </properties> | |
| 164 | </destination> | |
| 165 | ||
| 156 | 166 | |
| 157 | 167 | <!-- Subtopics - HTTP --> |
| 158 | 168 | <destination id="messaging_HTTP_Poll_Subtopic" channels="my-http-poll"> |
| ... | ...@@ -0,0 +1,109 @@ | |
| 1 | <?xml version="1.0"?> | |
| 2 | <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" | |
| 3 | creationComplete="creationCompleteHandler();"> | |
| 4 | ||
| 5 | <!-- This example shows how to use a MultiTopicConsumer to listen for multiple | |
| 6 | subtopics. Before using subtopics, need | |
| 7 | to make sure that the following are set on the messaging destination: | |
| 8 | <properties> | |
| 9 | <server> | |
| 10 | <allow-subtopics>true</allow-subtopics> | |
| 11 | <subtopic-separator>.</subtopic-separator> | |
| 12 | </server> | |
| 13 | </properties> | |
| 14 | --> | |
| 15 | ||
| 16 | <mx:Panel id="mainPanel" height="100%" width="100%"> | |
| 17 | <mx:HBox> | |
| 18 | <mx:Label text="Producer"/> | |
| 19 | <mx:Button label="Send Foo{counter1} to subtopic1" click="sendMessage()"/> | |
| 20 | <mx:Button label="Send Foo{counter2} to subtopic2" click="sendMessage(false)"/> | |
| 21 | <mx:Button label="Disconnect1" click="producer1.disconnect();"/> | |
| 22 | <mx:Button label="Disconnect1" click="producer2.disconnect();"/> | |
| 23 | <mx:CheckBox label="Connected1?" selected="{producer1.connected}"/> | |
| 24 | <mx:CheckBox label="Connected2?" selected="{producer2.connected}"/> | |
| 25 | </mx:HBox> | |
| 26 | <mx:HBox> | |
| 27 | <mx:Label text="Consumer"/> | |
| 28 | <mx:Button label="Subcribe" click="consumer.subscribe();"/> | |
| 29 | <mx:Button label="Unsubscribe" click="consumer.unsubscribe();"/> | |
| 30 | <mx:Button label="Disconnect" click="consumer.disconnect();"/> | |
| 31 | <mx:CheckBox label="Connected?" selected="{consumer.connected}"/> | |
| 32 | <mx:CheckBox label="Subscribed?" selected="{consumer.subscribed}"/> | |
| 33 | </mx:HBox> | |
| 34 | <mx:Button label="Clear" click='ta.text = ""'/> | |
| 35 | <mx:TextArea id="ta" width="100%" height="100%"/> | |
| 36 | </mx:Panel> | |
| 37 | ||
| 38 | <mx:Producer id="producer1" | |
| 39 | destination="messaging_AMF_Stream_Subtopic" | |
| 40 | fault="faultHandler(event)" | |
| 41 | subtopic="chat.newton1"/> | |
| 42 | ||
| 43 | <mx:Producer id="producer2" | |
| 44 | destination="messaging_AMF_Stream_Subtopic" | |
| 45 | fault="faultHandler(event)" | |
| 46 | subtopic="chat.newton2"/> | |
| 47 | ||
| 48 | <mx:Script> | |
| 49 | <![CDATA[ | |
| 50 | import mx.messaging.MultiTopicConsumer; | |
| 51 | import mx.messaging.events.MessageFaultEvent; | |
| 52 | import mx.messaging.events.MessageEvent; | |
| 53 | import mx.messaging.messages.AsyncMessage; | |
| 54 | import mx.messaging.Producer; | |
| 55 | import mx.messaging.MultiTopicConsumer; | |
| 56 | ||
| 57 | import mx.logging.Log; | |
| 58 | import mx.logging.targets.TraceTarget; | |
| 59 | ||
| 60 | [Bindable] | |
| 61 | public var counter1:int = 0; | |
| 62 | ||
| 63 | [Bindable] | |
| 64 | public var counter2:int = 0; | |
| 65 | ||
| 66 | [Bindable] | |
| 67 | public var consumer:MultiTopicConsumer = new MultiTopicConsumer(); | |
| 68 | ||
| 69 | private function creationCompleteHandler():void | |
| 70 | { | |
| 71 | var target:TraceTarget = new TraceTarget(); | |
| 72 | target.includeLevel = true; | |
| 73 | target.filters = ["mx.messaging.*", "mx.rpc.*"]; | |
| 74 | Log.addTarget(target); | |
| 75 | ||
| 76 | consumer.destination = "messaging_AMF_Stream_Subtopic"; | |
| 77 | consumer.addEventListener(MessageEvent.MESSAGE, messageHandler); | |
| 78 | consumer.addEventListener(MessageFaultEvent.FAULT, faultHandler); | |
| 79 | consumer.addSubscription("chat.newton1"); | |
| 80 | consumer.addSubscription("chat.newton2"); | |
| 81 | } | |
| 82 | ||
| 83 | private function sendMessage(firstProducer:Boolean = true):void | |
| 84 | { | |
| 85 | var msg:AsyncMessage = new AsyncMessage(); | |
| 86 | if (firstProducer) | |
| 87 | { | |
| 88 | msg.body = "Foo" + counter1++; | |
| 89 | producer1.send(msg); | |
| 90 | } | |
| 91 | else | |
| 92 | { | |
| 93 | msg.body = "Foo" + counter2++; | |
| 94 | producer2.send(msg); | |
| 95 | } | |
| 96 | } | |
| 97 | ||
| 98 | private function messageHandler(event:MessageEvent):void | |
| 99 | { | |
| 100 | ta.text += "Consumer received message: "+ event.message.body + "\n"; | |
| 101 | } | |
| 102 | ||
| 103 | private function faultHandler(event:MessageFaultEvent):void | |
| 104 | { | |
| 105 | ta.text += "Received fault: " + event.faultString + "\n"; | |
| 106 | } | |
| 107 | ]]> | |
| 108 | </mx:Script> | |
| 109 | </mx:Application> | |
| 0 | 110 | \ No newline at end of file |