Data queues

The DataQueue classes allow the Java™ program to interact with server data queues.

IBM® i data queues have the following characteristics:

  • The data queue allows for fast communications between jobs. Therefore, it is an excellent way to synchronize and pass data between jobs.
  • Many jobs can simultaneously access the data queues.
  • Messages on a data queue are free format. Fields are not required as they are in database files.
  • The data queue can be used for either synchronous or asynchronous processing.
  • The messages on a data queue can be ordered in one the following ways:
    • Last-in first-out (LIFO). The last (newest) message that is placed on the data queue is the first message that is taken off the queue.
    • First-in first-out (FIFO). The first (oldest) message that is placed on the data queue is the first message that is taken off the queue.
    • Keyed. Each message on the data queue has a key associated with it. A message can be taken off the queue only by specifying the key that is associated with it.

The data queue classes provide a complete set of interfaces for accessing server data queues from your Java program. It is an excellent way to communicate between Java programs and programs on the server that are written in any programming language.

A required parameter of each data queue object is the AS400 object that represents the server that has the data queue or where the data queue is to be created.

Using the data queue classes causes the AS400 object to connect to the server. See managing connections for information about managing connections.

Each data queue object requires the integrated file system path name of the data queue. The type for the data queue is DTAQ. See integrated file system path names for more information.

Sequential and keyed data queues

The data queue classes support sequential and keyed data queues.:

Methods common to both types of queues are in the BaseDataQueue class. The DataQueue class extends the BaseDataQueue class in order to complete the implementation of sequential data queues. The BaseDataQueue class is extended by the KeyedDataQueue class to complete the implementation of keyed data queues.

When data is read from a data queue, the data is placed in a DataQueueEntry object. This object holds the data for both keyed and sequential data queues. Additional data available when reading from a keyed data queue is placed in a KeyedDataQueueEntry object that extends the DataQueueEntry class.

The data queue classes do not alter data that is written to or is read from the server data queue. The Java program must correctly format the data. The data conversion classes provide methods for converting data.

Example: Using DataQueue and DataQueueEntry

The following example creates a DataQueue object, reads data from the DataQueueEntry object, and then disconnects from the system.
Note: Read the Code example disclaimer for important legal information.
     // Create an AS400 object
     AS400 sys = new AS400("mySystem.myCompany.com");

     // Create the DataQueue object
     DataQueue dq = new DataQueue(sys, "/QSYS.LIB/MYLIB.LIB/MYQUEUE.DTAQ");

     // read data from the queue
     DataQueueEntry dqData = dq.read();

     // get the data out of the DataQueueEntry object.
     byte[] data = dqData.getData();

     // ... process the data

     // Disconnect since I am done using data queues
     sys.disconnectService(AS400.DATAQUEUE);