Blazeds核心包括RPC Service和Messageing Service。
详情可以参考:
http://www.iteye.com/topic/267517?
http://www.iteye.com/topic/267521
Messaging Service 你需要在messaging-config.xml下的service节点下添加一个子节点:<destination id="TestKenny"/>
如图1.
然后写Flex 代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" xmlns:pivot="com.flexmonster.pivot.*"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<s:Producer acknowledge="producer_acknowledgeHandler(event)"
fault="producer_faultHandler(event)"
destination="TestKenny" id="producer"/>
<s:Consumer id="consumer" destination="TestKenny" fault="producer_faultHandler(event)"
message="consumer_messageHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.messaging.events.MessageAckEvent;
import mx.messaging.events.MessageEvent;
import mx.messaging.events.MessageFaultEvent;
import mx.messaging.messages.AsyncMessage;
protected function button2_clickHandler(event:MouseEvent):void
{
var msg:AsyncMessage = new AsyncMessage();
msg.body = "aaa";
producer.send(msg);
}
protected function producer_acknowledgeHandler(event:MessageAckEvent):void
{
trace("producer_acknowledgeHandler");
}
protected function producer_faultHandler(event:MessageFaultEvent):void
{
trace("producer_faultHandler");
}
protected function consumer_messageHandler(event:MessageEvent):void
{
trace("consumer_messageHandler" + event.message.body);
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var channelSet:ChannelSet = new ChannelSet();
var myPollingAMF:AMFChannel = new AMFChannel("my-polling-amf","http://localhost:8400/blazeds/messagebroker/amfpolling");
myPollingAMF.pollingEnabled = true;
myPollingAMF.pollingInterval = 2000;
channelSet.addChannel(myPollingAMF);
consumer.channelSet = channelSet;
producer.channelSet = channelSet;
consumer.subscribe();
}
]]>
</fx:Script>
<s:Button label="Test" click="button2_clickHandler(event)"/>
</s:Application>
?然后重启下Tomcat,然后访问就可以了。
