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

SQL Anywhere 10.0.1 » QAnywhere » Writing QAnywhere Client Applications » Receiving QAnywhere messages

Receiving QAnywhere messages Next Page

Receiving messages synchronously


To receive messages synchronously, your application explicitly polls the queue for messages. It may poll the queue periodically, or when a user initiates a particular action such as clicking a Refresh button.

To receive messages synchronously (.NET)
  1. Declare message objects to hold the incoming messages.

    QAMessage msg;
    QATextMessage text_msg;
  2. Poll the message queue, collecting messages:

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

    See GetMessageNoWait method.

  3. To receive messages synchronously (C++)
    1. Declare message objects to hold the incoming messages.

      QAMessage * msg;
      QATextMessage * text_msg;
    2. Poll the message queue, collecting messages:

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

      See getMessageNoWait function.

    3. To receive messages synchronously (Java)
      1. Declare message objects to hold the incoming messages.

        QAMessage msg;
        QATextMessage text_message;
      2. Poll the message queue, collecting messages:

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

        See getMessageNoWait method.

      3. To receive messages synchronously (SQL)
        1. Declare an object to hold the message ID.

          begin
              declare @msgid varchar(128);
          
        2. Poll the message queue, collecting messages.

              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

          See: