`
hiphunter921
  • 浏览: 67099 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

AIR 中 使用 BlazeDS 消息服务

阅读更多

下载了wing酱的新浪微博AIR版,突然对Adobe AIR 产生了兴趣,刚巧遇上国内某聊天软件与某杀毒软件闹矛盾,本来就对这些软件没有好感的我就萌生一个念头,用AIR写个小小聊天工具,嘿嘿,我就立马想到了以前在RIA中使用过的BlazeDS RemoteObject,听说有个message service,所以来试试吧。

 

At the beginning, i tried to use the lastest version of sdk, so i download the Flex SDK 4.1(build 16076) and setup it successfully.

However, when I tried to run my AIR application, I ran into this error:

VerifyError: Error #1014: Class IIMEClient could not be found.

 

After doing a bit of research I found out that my Adobe AIR project’s application descriptor file wasn’t using the correct namespace for the AIR 2.0 SDK. According to the Adobe AIR 2 Release Notes:


 

I made the change in the descriptor file, and now everything works perfectly.

 

 

Flex code as follow:

 

<s:Producer id="producer"/>

<s:Consumer id="consumer"/>

import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.messaging.events.MessageEvent;
import mx.messaging.messages.AsyncMessage;

private function init():void{
	consumer= new Consumer();
	consumer.destination = "chat";
	var channel:AMFChannel=new AMFChannel("my-long-polling-amf","http://192.168.2.80:8080/TestFlex/spring/messagebroker/amflongpolling");
	var channelSet:ChannelSet = new ChannelSet();
	channelSet.addChannel(channel);
	consumer.channelSet=channelSet;
	consumer.addEventListener(MessageEvent.MESSAGE, function(event:MessageEvent):void{
	chatText.text += event.message.body.chatMessage + "\n"; 
        });
	consumer.subscribe();			
				
	producer.destination="chat";
	producer.channelSet= channelSet;
				
}
			
protected function button1_clickHandler(event:MouseEvent):void{
	var message:AsyncMessage = new AsyncMessage(); 
	message.body.chatMessage = inputChat.text; 
	producer.send(message); 
	inputChat.text = ""; 
}
 

The server side configuration:

In order to use long polling amf channel , I added some config into the service-config.xml:

<channel-definition id="my-long-polling-amf" class="mx.messaging.channels.AMFChannel">
	<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amflongpolling" class="flex.messaging.endpoints.AMFEndpoint"></endpoint>
	<properties>
		<polling-enabled>true</polling-enabled>
		<wait-interval-millis>-1</wait-interval-millis>
		<polling-interval-millis>100</polling-interval-millis>
		<max-waiting-poll-requests>50</max-waiting-poll-requests>
	</properties>	    
</channel-definition>
  • wait-interval-millis dictates how long the server should wait before returning a polling request. The default is 0. By setting it to -1, we are telling it to wait indefinitely until a message is to be routed to the client.
  • polling-interval-millis is the time interval between polling requests. Since we no longer need to pace the requests, we could safely set the interval to 0.
  • max-waiting-poll-requests caps the number of long polling clients. Since the server is not ackowleging right away during long polling, each client hogs one server thread. Once the cap is reached, any new clients fall back to simple polling clients.

We can see the specification of BlazeDS channel and endpoint from here .

 

I use the spring flex integration framework to my app. So i add some code to the applicationContext_flex.xml:

<flex:message-broker>		
	<flex:message-service default-channels="my-streaming-amf,my-long-polling-amf,my-polling-amf" />
</flex:message-broker>
	
<flex:message-destination id="chat" />

I defined a message destination named 'chat', hence the client side can use the name as the destination name.

 

tip:

  • In the AIR app, we also need to set a Flex Server to it for using blazeds.

  • To use a producer or a consumer , we need to set its channel.

In the RIA, i used to code like this:

var channelSet:ChannelSet = new ChannelSet(["my-long-polling-amf"]);

 

But in the AIR, there are some difference.  It need giving fully qualified url's including the port for the destination, and using addChannel function instead of just using the ChannelSet constructor:

var channel:AMFChannel=new AMFChannel("my-long-polling-amf","http://192.168.2.80:8080/TestFlex/spring/messagebroker/amflongpolling");

var channelSet:ChannelSet = new ChannelSet();
channelSet.addChannel(channel);

 

  • 大小: 33.8 KB
  • 大小: 34.6 KB
  • 大小: 79.1 KB
分享到:
评论

相关推荐

    Flex+BlazeDS+AIR+StreamingAMFChannel消息服务的即时聊天通信

    NULL 博文链接:https://shihuan830619.iteye.com/blog/1053917

    使用BlazeDS实现Flex与Java通信

    这是一份日文资料,但由于是PPT文件,看图即可学到如何配置...難しいことは置いといて、取り合えず 「BlazeDS」 を使って、Flash、AIRアプリから Javaオブジェクトのメソッドを呼び出すための手順書(Windows版)

    blazeDS(讲得很详细)

    BlazeDS是Adobe公司发布的免费开源产品,是该公司另一个收费产品LCDS的简化开源版本,BlazeDS使用Java语言在服务端提供如下功能:  1、提供客户端(Flex、AIR)通过AMF协议访问服务端(Java)数据的功能;  2、...

    BlazeDS开发者向导

    BlazeDS 是由 Adobe 公司免费发布,基于 Java 远程对象和 Web 消息服务, 面向 Adobe Flex 客户端和 AIR (Adobe Integrated Runtime) RIA (Rich Internet Application)进行数据处理和发布的服务器端技术。本...

    blazeds java源码部分

    BlazeDS is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe® Flex® and Adobe AIR...

    Flex Air 内部培训教程

    AIR工程實例搭建步驟詳解 1 开发环境 413 2. 系統架構圖 414 3 服務端開發 414 3.1 數據庫訪問配置 415 3.2 SPRING配置 415 3.3 IBATIS配置 418 3.4集成 BLAZEDS 419 3.4.1 定义接口 419 3.4.2 定義實現類 420 ...

    Java-Flex-air

    使用AIR/Flex/Action Script語言

    基于Flex4.X+BlazeDS+Spring3+JPA+Hibernate+MySQL实战开发在线书店

    Flex 是一个高效、免费的开源框架,可用于构建具有表现力的 Web应用程序,这些应用程序利用Adobe Flash Player和Adobe AIR, 运行时跨浏览器、桌面和操作系统实现一致的部署。虽然只能使用 Flex 框架构建 Flex应用...

    用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考

    《用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考》包含 ActionScript 语言元素、核心库、组件包以及适用于 Flash Platform 中的工具、运行时、服务和服务器的类。 使用预设过滤器按产品进行过滤 此...

    Flex on Java MEAP Jul 2010

    5. BlazeDS remoting and logging 6. Flex messenging Part 3: Going above and beyond 7. Securing and personalizing your application 8. Charting with DeGrafa 9. Desktop 2.0 with Adobe AIR 10. ...

    Flex.on.Java.rar

    5. BlazeDS remoting and logging 6. Flex messenging Part 3: Going above and beyond 7. Securing and personalizing your application 8. Charting with DeGrafa 9. Desktop 2.0 with Adobe AIR 10. ...

    Enterprise Development with Flex

    Develop a sample AIR application that automatically synchronizes local and remote databases to support your sales force Get solutions for leveraging AMF protocol and synchronizing Flex client data ...

    Advanced Flex 3 2008

    Who this book is for Every web developer interested... Most of the discussion hovers around BlazeDS, its alternatives and its possible extensions. Streaming is also touched upon. Chapter 8: PHP and Flex ...

    Flex体系架构剖析_QCon.pdf

    Flex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdfFlex体系架构剖析_QCon.pdf

Global site tag (gtag.js) - Google Analytics