Setting up the local message store

The local message store requires that you install QAnywhere. QAnywhere is located under the Synchronization and Messaging feature in the SQL Anywhere install program. In order to enable messaging in your SQL Anywhere database, you must install the QAnywhere schema into your SQL Anywhere database so that it can be used as a local message store. This is accomplished using the -sil option of the QAnywhere Agent for SQL Anywhere. The -sil option instructs the Agent to initialize the database as a local message store. The agent is simply used to initialize a local message store and is not needed any further. All QAnywhere objects created in the database belong to the ml_qa_message_group owner. Once your SQL Anywhere database has been initialized as a local message store, applications can use the QAnywhere client API to exchange messages.

 Create a local message store (.NET example)
  1. Create a SQL Anywhere database. You can omit this step if you are going to use an existing SQL Anywhere database.

    dbinit localmsgstore.db
  2. Install the QAnywhere schema into the SQL Anywhere database so that it can be used as a local message bus:

    qaagent -sil -c "dbf=localmsgstore.db;uid=dba;pwd=sql"
  3. Create a sender application to put messages in the message store. For information about using the .NET version of the QAnywhere client API, see QAnywhere .NET API reference for clients.



    using System;
    using System.IO;
    using iAnywhere.QAnywhere.Client;
    namespace sender
    {
    class sender
        {
            public static void Main() {
                try {
                    // QAnywhere initialization
                    QAManager mgr = QAManagerFactory.Instance.CreateQAManager();
                    // Be sure to set the DATABASE_TYPE property
                    mgr.SetProperty( "DATABASE_TYPE", "sqlanywhere" );
                    mgr.SetProperty( "CONNECT_PARAMS", "dbf=localmsgstore.db;uid=dba;pwd=sql" );
                    mgr.Open( AcknowledgementMode.IMPLICIT_ACKNOWLEDGEMENT );
                    mgr.Start();
                    // Create a text message
                    QATextMessage msg = mgr.CreateTextMessage();
                    msg.Text = "Sample text";
                    // Queue the message
                    mgr.PutMessage( "dbqueue", msg );
                    // QAnywhere finalization
                    mgr.Stop();
                    mgr.Close();
                    } catch( Exception exc ) {
                    Console.WriteLine( exc.Message );
                }
            }
        }
    }
  4. Compile the program using the following command line. You must have Visual Studio installed on your computer.

    csc /reference:"%SQLANY12%\Assembly\v2\iAnywhere.QAnywhere.Client.dll" sender.cs
  5. Create a receiver application to retrieve messages from the message store. For information about using the .NET version of the QAnywhere client API, see QAnywhere .NET API reference for clients.



    using System;
    using System.IO;
    using iAnywhere.QAnywhere.Client;
    namespace receiver
    {
    class receiver
    {
    public static void Main() {
    try {
    // QAnywhere initialization
    QAManager mgr = QAManagerFactory.Instance.CreateQAManager();
    // Be sure to set the DATABASE_TYPE property
    mgr.SetProperty( "DATABASE_TYPE", "sqlanywhere" );
    mgr.SetProperty( "CONNECT_PARAMS", "dbf=localmsgstore.db;uid=dba;pwd=sql" );
    mgr.Open( AcknowledgementMode.IMPLICIT_ACKNOWLEDGEMENT );
    mgr.Start();
    // Get the message
    QATextMessage msg = (QATextMessage)mgr.GetMessage( "dbqueue" );
    // Display the text
    Console.WriteLine( msg.Text );
    // QAnywhere finalization
    mgr.Stop();
    mgr.Close();
    } catch( Exception exc ) {
    Console.WriteLine( exc.Message );
    }
    }
    }
    }
  6. Compile the program using the following command line. You must have Visual Studio installed on your computer.

    csc /reference:"%SQLANY12%\Assembly\v2\iAnywhere.QAnywhere.Client.dll" receiver.cs
  7. Start the SQL Anywhere database:

    dbsrv12 localmsgstore.db
  8. Run the sender application:

    sender
  9. Run the receiver application:

    receiver

    The string "Sample Text" is displayed.

 Create a local message store (Java example)
  1. Create a SQL Anywhere database. You can omit this step if you are going to use an existing SQL Anywhere database.

    dbinit localmsgstore.db
  2. Install the QAnywhere schema into the SQL Anywhere database so that it can be used as a message bus.

    qaagent -sil -c "dbf=localmsgstore.db;uid=dba;pwd=sql"
  3. Create a sender application to put messages in the message store. For information about using the .NET version of the QAnywhere client API, see QAnywhere Java API reference for clients.



    import java.util.*;
    import ianywhere.qanywhere.client.*;
    public class sender
    {
    public static void main( String [] args ) {
    try {
    // QAnywhere initialization
    QAManager mgr = QAManagerFactory.getInstance().createQAManager();
    // Be sure to specify the DATABASE_TYPE
    mgr.setProperty( "DATABASE_TYPE", "sqlanywhere" );
    mgr.setProperty( "CONNECT_PARAMS", "dbf=localmsgstore.db;uid=dba;pwd=sql" );
    mgr.open( AcknowledgementMode.IMPLICIT_ACKNOWLEDGEMENT );
    mgr.start();
    // Create a text message
    QATextMessage msg = mgr.createTextMessage();
    msg.setText( "Sample text" );
    // Queue the message
    mgr.putMessage( "dbqueue", msg );
    // QAnywhere finalization
    mgr.stop();
    mgr.close();
    } catch( Exception exc ) {
    System.out.println( exc.getMessage() );
    }
    }
    }
  4. Compile the program using the following command line. You must have the Java JDK installed on your computer.

    javac  -cp "%SQLANY12%\java\qaclient.jar" sender.java
  5. Create a receiver application to retrieve messages from the message store. For information about using the Java version of the QAnywhere client API, see QAnywhere Java API reference for clients.



    import java.util.*;
    import ianywhere.qanywhere.client.*;
    public class receiver
    {
    public static void main( Strings [] args ) {
    try {
    // QAnywhere initialization
    QAManager mgr = QAManagerFactory.getInstance().createQAManager();
    // Be sure to set the DATABASE_TYPE property.
    mgr.setProperty( "DATABASE_TYPE", "sqlanywhere" );
    mgr.setProperty( "CONNECT_PARAMS", "dbf=localmsgstore.db;uid=dba;pwd=sql" );
    mgr.open( AcknowledgementMode.IMPLICIT_ACKNOWLEDGEMENT );
    mgr.start();
    // Get the message
    QATextMessage msg = (QATextMessage)mgr.getMessage( "dbqueue" );
    // Display the text
    System.out.println( msg.getText() );
    // QAnywhere finalization
    mgr.stop();
    mgr.close();
    } catch( Exception exc ) {
    System.out.println( exc.getMessage() );
    }
    }
    }
  6. Compile the program using the following command line. You must have the Java JDK installed on your computer.

    javac -cp "%SQLANY12%\java\qaclient.jar" receiver.java
  7. Start the SQL Anywhere database:

    dbsrv12 localmsgstore.db
  8. Run the sender application:

    java -cp ".\;%SQLANY12%\java\qaclient.jar;%SQLANY12%\java\jodbc.jar" sender
  9. Run the receiver application:

    java -cp ".\;%SQLANY12%\java\qaclient.jar;%SQLANY12%\java\jodbc.jar" receiver

    The string "Sample Text" is displayed.

 Cleaning the message store
 Viewing messages