论坛首页 编程语言技术论坛

flex message suptopic filter使用subtopic过滤信息

浏览 3438 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-05-09  

官方说明,看的真晕,谁有blazeds中文翻译麻烦给一份

In the Consumer component, use the subtopic property to define the subtopic that a message must be sent to for
it to be received. You can specify a literal String value for the subtopic property. Use the wildcard character (*) in
the Consumer.subtopic property to receive messages from more than one subtopic.

大概意思,你可以指定一个字面意思的subtopic属性,用通配符来接收不止一个subtopic(ru foo.*可以接收 foo.a,foo.b发布的信息);
The Messaging Service supports single-token wildcards in the subtopic String. If the wildcard character is the last
character in the String, it matches any tokens in that position or in any subsequent position.

messaging Service支持单一的一个通配符在subtopic中 如 subtopic="*"表示接收所有信息,*也不写,就什么也收不到

 For example, the
Consumer component specifies the subtopic as "foo.*". It matches the subtopics "foo.bar" and "foo.baz", and also
"foo.bar.aaa" and "foo.bar.bbb.ccc".

 

foo.*可以收到如 foo.bar foo.baz foo.bar.aaa foo.bar.bbb.ccc这样的producer指定的subtopic的信息


If the wildcard character is in any position other than the last position, it only matches a token at that position. For
example, a wildcard character in the second position matches any tokens in the second position of a subtopic value,
but it does not apply to multiple tokens. Therefore, if the Consumer component specifies the subtopic as "foo.*.baz",
it matches the subtopics "foo.bar.baz" and "foo.aaa.baz", but not "foo.bar.cookie".
To send a message from a Producer component to a destination and a subtopic, set the destination and subtopic

 

producer 指定foo.*.baz

consumer能接收到的信息有 foo.bar.baz foo.aa.baz 而foo.bar.cookie不能受到,应为不匹配


properties, and then call the send() method, as the following example shows:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
	
<mx:Script>
<![CDATA[
	import mx.messaging.channels.AMFChannel;
import mx.messaging.*;
import mx.messaging.messages.*;
import mx.messaging.events.*;
private function useSubtopic():void {
var message:AsyncMessage = new AsyncMessage();
producer.subtopic = "chat.fds.newton";
message.body=txt.text;
// Generate message.
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="ChatTopic"/>
	<mx:TextInput x="193" y="38" text="使用subTopic过滤消息" id="txt"/>
	<mx:Button x="230" y="85" label="send" click="useSubtopic()"/>


</mx:Application>

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init();logon()">
<mx:Script>
<![CDATA[
	import mx.messaging.channels.AMFChannel;
import mx.messaging.*;
import mx.messaging.messages.*;
import mx.messaging.events.*;
private function messageHandler(event:MessageEvent):void {
// Handle message event.
ta.text += event.message.body + "\n";
}
private function logon():void {
consumer.subtopic = "*"; 
//不写consumer.subtopic就接收不到任何producer发送的subtopic指定的信息(producer指定了subtopic,
//consumer必须也指定subtopic才能受到信息)
//chat.fds.* 或者 chat.fds.newton都可以受到信息,可以使用通配符 c.*这样就收不到信息
consumer.subscribe();
}
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="ChatTopic"
message="messageHandler(event);"/>
<mx:TextArea id="ta" width="100%" height="100%"/>
</mx:Application>

  message-config.xml官方说明

To allow subtopics for a destination, set the allow-subtopics element to true in the destination definition in the
messaging-config.xml file. The subtopic-separator element is optional and lets you change the separator
character; the default value is "." (period).
 允许一个destination指定一个subtopics  在message-config.xml重的destination设置allow-subtopics属性为true 设置分隔符 subtopic-separator 默认是 .(一个点)

<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service" 
    class="flex.messaging.services.MessageService">

    <adapters>
        <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
        <!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
    </adapters>

    <default-channels>
        <channel ref="my-polling-amf"/>
    </default-channels>
	<destination id="mychat">//这是我上个过滤例子用的
		
	</destination>
	<destination id="ChatTopic">
<properties>
<network>
<subscription-timeout-minutes>0</subscription-timeout-minutes>
</network>
<server>
<message-time-to-live>0</message-time-to-live>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>
</properties>


</destination>
</service>

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics