Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » QAnywhere » QAnywhere 参考 » QAnywhere 属性 » 客户端消息存储库属性 » 自定义客户端消息存储库属性

 

使用自定义客户端消息存储库属性特性

客户端消息存储库属性可以具有您定义的特性。可通过在属性名后面追加一个点,并在其后跟有特性名,来定义特性。此功能的主要用途是:可以在传输规则中使用有关您的网络的信息。

将 UltraLite 用作客户端消息存储库时,对属性特性的支持有限。UltraLite 消息存储库只支持预定义的 ias_Network 属性。

示例(仅限 SQL Anywhere)

以下简单示例说明了自定义客户端消息存储库属性特性的设置方法。在此例中,Object 属性有两个特性:Shape 和 Color。Shape 特性的值为 Round,Color 特性的值为 Blue。

// C++ example.
mgr->setStringStoreProperty( "Object.Shape", "Round" );
mgr->setStringStoreProperty( "Object.Color", "Blue" );
// C# example.
mgr.SetStoreStringProperty( "Object.Shape", "Round" );
mgr.SetStringStoreProperty( "Object.Color", "Blue" );
// Java example
mgr.setStringStoreProperty( "Object.Shape", "Round" );
mgr.setStringStoreProperty( "Object.Color", "Blue" );
-- SQL example
BEGIN
    CALL ml_qa_setstoreproperty( 'Object.Shape', 'Round' );
    CALL ml_qa_setstoreproperty( 'Object.Color', 'Blue' );
    COMMIT;
END

所有客户端消息存储库属性都有 Type 属性(无初始值)。Type 特性的值必须是另一个属性的名称。设置某个属性的 Type 特性时,该属性将继承指派给它的属性的特性。在以下示例中,Object 属性继承了 Circle 属性的特性。因此,Object.Shape 的值为 Round,Object.Color 的值为 Blue。

// C++ example
QAManager qa_manager;
qa_manager->setStoreStringProperty( "Circle.Shape", "Round" );
qa_manager->setStoreStringProperty( "Circle.Color", "Blue" );
qa_manager->setStoreStringProperty( "Object.Type", "Circle" );
// C# example
QAManager qa_manager;
qa_manager.SetStringStoreProperty( "Circle.Shape", "Round" );
qa_manager.SetStringStoreProperty( "Circle.Color", "Blue" );
qa_manager.SetStringStoreProperty( "Object.Type", "Circle" );
// Java example
QAManager qa_manager;
qa_manager.setStringStoreProperty( "Circle.Shape", "Round" );
qa_manager.setStringStoreProperty( "Circle.Color", "Blue" );
qa_manager.setStringStoreProperty( "Object.Type", "Circle" );
-- SQL example
BEGIN
    CALL ml_qa_setstoreproperty( 'Circle.Shape', 'Round' );
    CALL ml_qa_setstoreproperty( 'Circle.Color', 'Blue' );
    CALL ml_qa_setstoreproperty( 'Object.Type', 'Circle');
    COMMIT;
END
示例

以下 C# 示例介绍了如何使用消息存储库属性,将您的网络信息提供给传输规则。

假定您的 Windows 膝上型计算机具有以下网络连接选项:LAN、Wireless LAN 和 Wireless WAN。名为 My LAN Card 的网卡提供通过 LAN 对网络的访问。名为 My Wireless LAN Card 的网卡提供通过 Wireless LAN 对网络的访问。名为 My Wireless WAN Card 的网卡提供通过 Wireless WAN 对网络的访问。

假定您要开发一个消息传递应用程序,该应用程序在使用 LAN 或 Wireless LAN 连接时,将所有消息都发送到服务器,在使用 Wireless WAN 连接时,仅发送高优先级消息。将高优先级消息定义为优先级大于等于 7 的消息。

首先,查找网络适配器的名称。一旦插入网卡并安装了驱动程序,网络适配器的名称就固定了。要查找特殊网卡的名称,可通过该适配器连接到网络,然后使用 -vn 选项运行 qaagent。QAnywhere 代理采用以下形式显示网络适配器名:

"Listener thread received message '[netstat] network-adapter-name !...'

其次,为每个网络类型分别定义三个客户端消息存储库属性:LAN、WLAN 和 WWAN。为每个属性指派一个 Cost 特性。Cost 特性是 1 到 3 之间的值,表示网络的使用成本。值 1 表示最低成本。

QAManager qa_manager;
qa_manager.SetStoreProperty( "LAN.Cost", "1" );
qa_manager.SetStoreProperty( "WLAN.Cost", "2" );
qa_manager.SetStoreProperty( "WWAN.Cost", "3" );

然后,定义三个客户端消息存储库属性(每个使用的网卡定义一个)。属性名必须与网卡名匹配。通过向 Type 特性指派网络类型,为每个属性指派适当的网络分类。因此,每个属性都将继承为其指派的网络类型的特性。

QAManager qa_manager;
qa_manager.SetStoreProperty( "My LAN Card.Type", "LAN" );
qa_manager.SetStoreProperty( "My Wireless LAN Card.Type", "WLAN" );
qa_manager.SetStoreProperty( "My Wireless WAN Card.Type", "WWAN" );

在网络连接建立后,QAnywhere 将自动根据正在使用的网络将 ias_Network 属性的 Adapter 特性定义为 My LAN Card、My Wireless LAN Card 或 My Wireless WAN Card 中的一个。同样,它自动将 ias_Network 属性的 Type 特性定义为 My LAN Card、My Wireless LAN Card 或 My Wireless WAN Card 中的一个,以使 ias_Network 属性继承正在使用的网络的特性。

最后,创建以下传输规则。

automatic=ias_Network.Cost < 3 or ias_Priority >= 7

有关传输规则的详细信息,请参见QAnywhere 传输和删除规则