Collection Contents 上一页 下一页 PDF

QAnywhere 用户指南

编写 QAnywhere 客户端应用程序

同步接收消息


为了同步接收消息,应用程序显式轮询队列检查是否有消息。可以定期或当用户启动某个特定的操作(例如,单击 [刷新] 按钮)时轮询队列。

同步接收消息 (C++)

  1. 声明消息对象以保存进来的消息。

    QAMessage *      msg;
    QATextMessage *   text_msg;
  2. 轮询消息队列,接收消息:

    if( mgr->start() ) {
        for( ;; ) {
            msg = mgr->getMessageNoWait( "queue_name" );
            if( msg == NULL )  break;
            text_msg = msg->castToTextMessage();
            if( text_msg != NULL ) {
                // display text message using 
                // text_msg->getText()
            }
            sleep( time-period );
        }
        mgr->stop();
    }

同步接收消息 (.NET)

  1. 声明消息对象以保存进来的消息。

    QAMessage       msg;
    QATextMessage    text_msg;
  2. 轮询消息队列,收集消息:

    if(mgr.start()  )  {
      for(;;) {
        msg = mgr.GetMessageNoWait("queue_name");
        if( msg == null ) break;
        addMessage( msg );
      }
      mgr.stop();
    }

Collection Contents 上一页 下一页 PDF