有关使用通知的背景信息,请参见使用推式通知进行消息传递的方案。
通知和网络状态更改都作为系统消息发送到 QAnywhere 应用程序。系统消息与其它消息完全相同,只是在名为 system 的单独的队列中接收。
例如,下面的 C# 代码处理系统消息和标准消息。代码假定您已经定义了 onMessage 和 onSystemMessage 处理函数(它们实现处理消息的应用程序逻辑)。
// Declare the message listener and system listener private QAManager.MessageListener _receiveListener; private QAManager.MessageListener _systemListener; ... // Create a MessageListener that uses the appropriate message handlers _receiveListener = new QAManager.MessageListener( onMessage ); _systemListener = new QAManager.MessageListener( onSystemMessage ); ... // Register the message handler mgr.SetMessageListener( queue-name, _receiveListener ); mgr.SetMessageListener( "system", _systemListener );
系统消息处理程序可以查询消息属性以确定消息包含的信息。消息类型属性指示消息是否包含网络状态通知。例如,对于消息 msg:
if( msg.PropertyExists(MessageProperties.MSG_TYPE) ) {
msg_type=(MessageType)msg.GetIntProperty(...);
...
} else {
// Process regular message
}msg_type = (MessageType)msg.GetIntProperty( MessageProperties.MSG_TYPE );
if( msg_type == MessageType.NETWORK_STATUS_NOTIFICATION ) {
// Process a network status change
} else if ( msg_type == MessageType.PUSH_NOTIFICATION ) {
// Process a push notification
} else if ( msg_type == MessageType.REGULAR ) {
// This message type should not be received on the system
// queue. Take appropriate action here.
}SQL Anywhere Studio 9.0.2
版权所有 © 1989–2005 Sybase, Inc. 部分版权所有 © 2001–2005 iAnywhere Solutions, Inc. 保留所有权利。