[Previous Example | Main Tutorial Page]

Message queue: Example 3 of 3

Use the following as an example for your program.

//////////////////////////////////////////////////////////////////////////////////
//
// Example using the Message Queue function of the IBM Toolbox for Java
//
//////////////////////////////////////////////////////////////////////////////////
//
// This source is an example of IBM Toolbox for Java "Message Queue".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind.  The implied warranties of
// merchantability and fitness for a particular purpose are
// expressly disclaimed.
//
// IBM Toolbox for Java
// (C) Copyright IBM Corp. 1999
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
//////////////////////////////////////////////////////////////////////////////////

package examples;


import java.io.*;
import java.util.*;
import com.ibm.as400.access.*;

public class displayMessages extends Object
{

   public static void main(String[] parameters)
   {
      displayMessages me = new displayMessages();

      me.Main(parameters);

      System.exit(0);
   }


   void displayMessage()
   {
   }


   void Main(String[] parms)
   {
      try
      {
         AS400 system = new AS400();

         if (parms.length > 0)
            system.setSystemName(parms[0]);

         MessageQueue queue = new MessageQueue(system, MessageQueue.CURRENT); 1 Click to display a detailed explanation


                  Enumeration e = queue.getMessages(); 2 Click to display a detailed explanation

                  while (e.hasMoreElements())
                  {

                      QueuedMessage message = (QueuedMessage) e.nextElement(); 3 Click to display a detailed explanation
                      System.out.println(message.getText()); 4 Click to display a detailed explanation
                   }
              }
              catch (Exception e)
              {
                 e.printStackTrace();
              }
         }
}

  1. The purpose of this program is to display messages an an AS/400 message queue. The MessageQueue object of the AS/400 Toolbox for Java is used for this task. When the message queue object is constructed, the parameters are the AS400 object and the message queue name. The AS400 object indicates which AS/400 contains the resource, and the message queue name identifies which message queue on the AS/400. In this case, a constant is used, which tells the message queue object to access the queue of the signed-on user.

  2. The message queue object gets a list of messages from the AS/400. A connection to the AS/400 is made at this point.

  3. Remove a message from the list. The message is in the IBM Toolbox for Java program's QueuedMessage object.

  4. Print the text of the message.




Previous