Sun Java System Messaging Server 6 2005Q4 MTA Developer's Reference

Processing the Message Queue

This section describes the steps undertaken by each execution thread created by mtaDequeueStart(). Each execution thread processes a subset of the channel’s queued messages by repeatedly calling the caller-supplied processing routine, process_message().

To process queued messages, a processing thread takes the following steps:

  1. The thread sets ctx2 to have the value NULL:

    ctx2 = NULL;

    For information on the process_message() arguments, see The process_message() Routine.

  2. The execution thread communicates with the Job Controller to obtain a message file to process. If there are no more message files to process, then go to Step 9.

  3. For the message file, the execution thread creates a dequeue context that maintains the dequeue processing state for that message file.

  4. The execution thread then invokes the caller-supplied process_message() routine, passing to it the dequeue context created in Processing the Message Queue, as shown in the example that follows:

    istat = process_message(&ctx2, ctx1, &dq_ctx, env_from, env_from_len);

    For information on the call arguments for process_message(), see The process_message() Routine.

  5. The process_message() routine then attempts to process the message, ultimately removing it from the channel’s queue, or leaving the message file for a later processing attempt.

  6. If mtaDequeueMessageFinish() was not called before process_message() returned, then the queued message is deferred. That is, its underlying message file is left in the channel’s queue and a later processing attempt is scheduled.

  7. The dequeue context is destroyed.

  8. If the process_message() routine did not return the MTA_ABORT status code, then repeat this cycle starting at Step 2.

  9. If a caller-supplied process_done() routine was passed to mtaDequeueStart(), it is called now, for example:

  10. process_done(&ctx2, ctx1);

    Through the process_done() routine, the program can perform any cleanup necessary for the execution thread. For example, freeing up any private context and associated resources stored in the ctx2 call argument.

    For a description of the process_done() routine, see The process_done() Routine, as well as process_done() Routine.

  11. The thread exits.

    For an example of how state (context) may be preserved within an execution thread and across calls to process_message(), A Complex Dequeuing Example.