代码都是官方的,因为我在本地测试,所以得设置channelSet
producer可以通过设置AsyncMessage的header 设置消息头
cousumer可以通过设置selector来过滤消息(消息头中指定的消息),selector不写,说明不过滤,可以收到
写了,会跟消息头中的字段匹配,好像字符串不行如
message.headers["prop1"] = 10; //指定消息头 10不能是字符串
selector="prop1 = 10" //可以用比较运算符 如:selector="prop1 >5"
如果不想接收某个信息,把selector设置为不匹配的如:selector="prop1 > 10"这样就接收不到消息。
这样就可以通过 过滤消息来 分组发 ,p2p ,发给所有人。(可能这样更复杂了,希望高人提出更简单的办法)
producer_filter.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"> <mx:Script> <![CDATA[ import mx.messaging.channels.AMFChannel; import mx.messaging.*; import mx.messaging.messages.*; import mx.messaging.events.*; private function sendMessage():void { init(); var message:AsyncMessage = new AsyncMessage(); message.headers = new Array(); message.headers["prop1"] = 10; //指定消息头 message.body = input.text; producer.send(message); } //设置channelSet private function init(){ var url="http://localhost:8400/BlazedsMessage/"; //随便的以个blazeds应用 // var myStreamingAMF:StreamingAMFChannel = new StreamingAMFChannel(url+"my-streaming-amf", url+"messagebroker/streamingamf"); var myPollingAMF:AMFChannel = new AMFChannel(url+"my-polling-amf", url+"messagebroker/amfpolling"); myPollingAMF.pollingEnabled = true;//轮询 myPollingAMF.pollingInterval = 1000;//隔多长时间询问一次 1miao var channelSet:ChannelSet = new ChannelSet(); // channelSet.addChannel(myStreamingAMF); channelSet.addChannel(myPollingAMF); producer.channelSet = channelSet; } ]]> </mx:Script> <mx:Producer id="producer" destination="mychat"> </mx:Producer> <mx:TextInput id="userName"/> <mx:TextInput id="input"/> <mx:Button label="Send" click="sendMessage();"/> </mx:Application>
consumer_filter.mxml
<?xml version="1.0" encoding="utf-8"?> <!-- ds\messaging\CreateConsumerMXML.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="logon();"> <mx:Script> <![CDATA[ import mx.messaging.channels.AMFChannel; import mx.messaging.*; import mx.messaging.messages.*; import mx.messaging.events.*; // Subscribe to destination. private function logon():void { init(); consumer.subscribe();//订阅 } // Write received message to TextArea control. //收到信息 private function messageHandler(event:MessageEvent):void { // Handle message event. ta.text += event.message.body + "\n"; } private function init(){ var url="http://localhost:8400/BlazedsMessage/"; // var myStreamingAMF:StreamingAMFChannel = new StreamingAMFChannel(url+"my-streaming-amf", url+"messagebroker/streamingamf"); var myPollingAMF:AMFChannel = new AMFChannel(url+"my-polling-amf", url+"messagebroker/amfpolling"); myPollingAMF.pollingEnabled = true; myPollingAMF.pollingInterval = 1000; var channelSet:ChannelSet = new ChannelSet(); // channelSet.addChannel(myStreamingAMF); channelSet.addChannel(myPollingAMF); consumer.channelSet = channelSet; } ]]> </mx:Script> <mx:Consumer id="consumer" destination="mychat" selector="prop1 = 10" message="messageHandler(event);"> <!--上边的selector可以改成 selector="prop1 > 9" 也能受到信息,说明可以用比较 官方文档也很少。郁闷--> </mx:Consumer> <mx:TextArea id="ta" width="100%" height="100%"/> </mx:Application>
服务器端 message-config.xml
我不能回复,回答了15道问题,10道错误,回帖那人你说的对的 selector="prop1 > 9 ;
prop1>9是个sql表达式 意思是你还可以 这样between and