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

SQL Anywhere 12.0.0 (中文) » QAnywhere » 编写 QAnywhere 客户端应用程序

 

发送 QAnywhere 消息

以下过程介绍如何从 QAnywhere 应用程序发送消息。这些过程假定您已创建并打开了一个 QAManager 对象。

从您的应用程序发送一条消息,并不能确保该消息是从您的设备传送的。这一操作只是把消息放在一个队列上等待传送。QAnywhere 代理执行将消息发送到 MobiLink 服务器的任务,接着 MobiLink 服务器再将消息传送到消息所要到达的目标。

有关消息传输的发生时间的详细信息,请参见确定在客户端进行消息传输的时间

 ♦  发送消息 (.NET)
  1. 创建一条新消息。

    您可以分别使用 CreateTextMessage() 或 CreateBinaryMessage(),来创建文本消息或二进制消息。

    QATextMessage     msg;
    msg = mgr.CreateTextMessage();
  2. 设置消息属性。

    使用 QATextMessage 或 QABinaryMessage 类的方法来设置属性。

    请参见QAnywhere 消息

  3. 将消息放入队列,准备发送。

    mgr.PutMessage( "store-id\\queue-name", msg );

    其中,store-idqueue-name 是组合构成目标地址的字符串。

    请参见PutMessage 方法确定在客户端进行消息传输的时间

 ♦  发送消息 (C++)
  1. 创建一条新消息。

    您可以分别使用 createTextMessage() 或 createBinaryMessage(),来创建文本消息或二进制消息。

    QATextMessage *   msg;
    msg = mgr->createTextMessage();
  2. 设置消息属性。

    使用 QATextMessage 或 QABinaryMessage 类的方法来设置消息属性。

    请参见QAnywhere 消息

  3. 将消息放入队列,准备发送。

    if( msg != NULL ) {
      if( !mgr->putMessage( "store-id\\queue-name", msg ) ) {
        // Display error using mgr->getLastErrorMsg().
        }
        mgr->deleteMessage( msg );
    }

    其中,store-idqueue-name 是组合构成目标地址的字符串。

    请参见putMessage 方法确定在客户端进行消息传输的时间

 ♦  发送消息 (Java)
  1. 创建一条新消息。

    您可以分别使用 QAManagerBase.createTextMessage() 或 QAManagerBase.createBinaryMessage(),来创建文本消息或创建二进制消息。

    QATextMessage msg;
    msg = mgr.createTextMessage();
  2. 设置消息属性。

    使用 QATextMessage 或 QABinaryMessage 方法来设置消息属性。

    请参见QAnywhere 消息

  3. 将消息放入队列。

    mgr.putMessage("store-id\\queue-name", msg);

请参见putMessage 方法确定在客户端进行消息传输的时间

 ♦  发送消息 (SQL)
  1. 声明保存消息 ID 的变量。

    begin
        declare @msgid varchar(128);
  2. 创建一条新消息。

        set @msgid = ml_qa_createmessage();
  3. 设置消息属性。

    有关详细信息,请参见消息属性

  4. 将消息放入队列。

        call ml_qa_putmessage( @msgid, 'clientid\queuename' );
        commit;
    end

请参见ml_qa_putmessage确定在客户端进行消息传输的时间


实现事务性消息传递