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 消息

 

同步接收消息

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

♦  同步接收消息 (.NET)
  1. 声明消息对象以保存进来的消息。

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

    for(;;) {
        msg = mgr.GetMessageNoWait("queue-name");
        if( msg == null ) {
          break;
        }
        addMessage( msg );
      }

    请参见GetMessageNoWait 方法

♦  同步接收消息 (C++)
  1. 声明消息对象以保存进来的消息。

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

    for( ;; ) {
        msg = mgr->getMessageNoWait( "queue-name" );
        if( msg == NULL ) {
          break;
        }
        addMessage(msg);
      }

    请参见getMessageNoWait 函数

♦  同步接收消息 (Java)
  1. 声明消息对象以保存进来的消息。

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

    if(mgr.start()) {
      for ( ;; ) {
        msg = mgr.getMessageNoWait("queue-name");
        if ( msg == null ) {
          break;
        }
        addMessage(msg);
      }
      mgr.stop();
    }

    请参见getMessageNoWait 方法

♦  同步接收消息 (SQL)
  1. 声明保存消息 ID 的对象。

    begin
        declare @msgid varchar(128);
    
  2. 轮询消息队列,收集消息。

        loop
            set @msgid = ml_qa_getmessagenowait( 'myaddress' );
            if @msgid is null then leave end if;
            message 'a message with content ' || ml_qa_gettextcontent( @msgid ) || ' has been received';
        end loop;
        commit;
    end

    请参见: