AIR 中 使用 BlazeDS 消息服务

本文详细介绍了如何利用Adobe AIR和BlazeDSRemoteObject创建一个简单的聊天应用,包括设置Flex SDK、解决类未找到错误、配置服务器端长轮询AMF通道、客户端与服务器通信及服务器端配置等关键步骤。

下载了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);

 

采用PyQt5框架Python编程语言构建图书信息管理平台 本项目基于Python编程环境,结合PyQt5图形界面开发库,设计实现了一套完整的图书信息管理解决方案。该系统主要面向图书馆、书店等机构的日常运营需求,通过模块化设计实现了图书信息的标准化管理流程。 系统架构采用典型的三层设计模式,包含数据存储层、业务逻辑层和用户界面层。数据持久化方案支持SQLite轻量级数据库MySQL企业级数据库的双重配置选项,通过统一的数据库操作接口实现数据存取隔离。在数据建模方面,设计了包含图书基本信息、读者档案、借阅记录等核心数据实体,各实体间通过主外键约束建立关联关系。 核心功能模块包含六大子系统: 1. 图书编目管理:支持国际标准书号、中国图书馆分类法等专业元数据的规范化著录,提供批量导入单条录入两种数据采集方式 2. 库存动态监控:实时追踪在架数量、借出状态、预约队列等流通指标,设置库存预警阈值自动提醒补货 3. 读者服务管理:建立完整的读者信用评价体系,记录借阅历史违规行为,实施差异化借阅权限管理 4. 流通业务处理:涵盖借书登记、归还处理、续借申请、逾期计算等标准业务流程,支持射频识别技术设备集成 5. 统计报表生成:按日/月/年周期自动生成流通统计、热门图书排行、读者活跃度等多维度分析图表 6. 系统维护配置:提供用户权限分级管理、数据备份恢复、操作日志审计等管理功能 在技术实现层面,界面设计遵循Material Design设计规范,采用QSS样式表实现视觉定制化。通过信号槽机制实现前后端数据双向绑定,运用多线程处理技术保障界面响应流畅度。数据验证机制包含前端格式校验后端业务规则双重保障,关键操作均设有二次确认流程。 该系统适用于中小型图书管理场景,通过可扩展的插件架构支持功能模块的灵活组合。开发过程中特别注重代码的可维护性,采用面向对象编程范式实现高内聚低耦合的组件设计,为后续功能迭代奠定技术基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值