NAME

MQSeries::Queue -- OO interface to the MQSeries Queue objects

SYNOPSIS

  use MQSeries;
  use MQSeries::Queue;
  use MQSeries::Message;

  #
  # Open a queue for output, loop getting messages, updating some
  # database with the data.
  # 
  my $queue = MQSeries::Queue->new
    (
     QueueManager 	=> 'some.queue.manager',
     Queue 		=> 'SOME.QUEUE',
     Mode 		=> 'input_exclusive',
    )
    or die("Unable to open queue.\n");

  while ( 1 ) {

    my $getmessage = MQSeries::Message->new;

    $queue->Get
      (
       Message => $getmessage,
       Sync => 1,
      ) or die("Unable to get message\n" .
	       "CompCode = " . $queue->CompCode() . "\n" .
	       "Reason = " . $queue->Reason() . "\n");

    if ( UpdateSomeDatabase($getmessage->Data()) ) {
        $queue->Commit()
	  or die("Unable to commit changes to queue.\n" .
		 "CompCode = " . $queue->CompCode() . "\n" .
		 "Reason = " . $queue->Reason() . "\n");
    }
    else {
        $queue->Backout()
	  or die("Unable to backout changes to queue.\n" .
		 "CompCode = " . $queue->CompCode() . "\n" .
		 "Reason = " . $queue->Reason() . "\n");
    }

  }

  #
  # Put a message into the queue, using Storable to allow use of
  # references as message data. (NOTE: this is done for you if use the
  # MQSeries::Message::Storable class.)
  #
  use Storable;
  my $queue = MQSeries::Queue->new
    (
     QueueManager 	=> 'some.queue.manager',
     Queue 		=> 'SOME.QUEUE',
     Mode 		=> 'output',
     PutConvert        	=> \&Storable::nfreeze,
     GetConvert 	=> \&Storable::thaw,
    )
    or die("Unable to open queue.\n");

  my $putmessage = MQSeries::Message->new
    (
     Data => {
	      a => [qw( b c d )],
	      e => {
		    f => "Huh?",
		    g => "Wow!",
		   },
	      h => 42,
	     },
    );

  $queue->Put( Message => $putmessage )
    or die("Unable to put message onto queue.\n" .
	   "CompCode = " . $queue->CompCode() . "\n" .
	   "Reason = " . $queue->Reason() . "\n");

  #
  # Alternate mechanism for specifying the conversion routines.
  #
  my $queue = MQSeries::Queue->new
    (
     QueueManager 	=> 'some.queue.manager',
     Queue 		=> 'SOME.QUEUE',
     Mode 		=> 'output',
    )
    or die("Unable to open queue.\n");

  my $putmessage = MQSeries::Message->new
    (
     Data => {
	      a => [qw( b c d )],
	      e => {
		    f => "Huh?",
		    g => "Wow!",
		   },
	      h => 42,
	     },
    );

  $queue->Put(
	      Message => $putmessage
  	      PutConvert => \&Storable::freeze,
	     )
    or die("Unable to put message onto queue.\n" .
	   "CompCode = " . $queue->CompCode() . "\n" .
	   "Reason = " . $queue->Reason() . "\n");

DESCRIPTION

The MQSeries::Queue object is an OO mechanism for opening MQSeries Queues, and putting and getting messages from those queues, with an interface which is much simpler than the full MQI.

This module is used together with MQSeries::QueueManager and MQSeries::Message. These objects provide a subset of the MQI, with a simpler interface.

The primary value added by this interface is logic to retry the connection under certain failure conditions. Basically, any Reason Code which represents a transient condition, such as a Queue Manager shutting down, or a connection lost (possible due to a network glitch?), will result in the MQCONN call being retried, after a short sleep. See below for how to tune this behavior.

This is intended to allow developers to write MQSeries applications which recover from short term outages without intervention. This behavior is critically important to the authors applications, but may not be right for yours.

METHODS

new

The arguments to the constructor are a hash, with the following key/value pairs (required keys are marked with a '*'):

Key                		Value
===                		=====
QueueManager      		String, or MQSeries::QueueManager object
Queue*             		String, or ARRAY reference (distribution list)
Mode*              		String
Options*           		MQOPEN 'Options' values
CloseOptions	     		MQCLOSE 'Options' values
DisableAutoResize  		Boolean
NoAutoOpen    		Boolean
ObjDesc            		HASH Reference
Carp               		CODE Reference
PutConvert         		CODE Reference
GetConvert         		CODE Reference
CompCode           		Reference to Scalar Variable
Reason             		Reference to Scalar Variable

NOTE: Only one or the 'Options' or 'Mode' keys can be specified. They are mutually exclusive. If 'NoAutoOpen' is given, then both 'Options' and 'Mode' are optional, as they canbe passed directly to the Open() method.

QueueManager

The Queue Manager to connect to must be specified, unless you want to connect to the "default" queue manager, and your site supports such a configuration.

This can either be an MQSeries::QueueManager object, or the name of the Queue Manager. Since the MQSeries::Queue object will internally create the MQSeries::QueueManager object, if given a name, this is the simpler mechanism.

Code which opens multiple Queues on a single Queue Manager can be slightly optimized by creating the QueueManager object explicitly, and then reusing it for the multiple MQSeries::Queue objects which must be instantiated. This will avoid a few unnecesary MQCONN calls, but this overhead should prove to be minimal in most cases.

If the "default" queue manager is to be used, then the QueueManager argument can either be specified as the empty string "", or just omitted entirely.

Queue

The name of the Queue obviously must be specified. This can be either a plain ASCII string, indicating a single queue, or an ARRAY reference, indicating a distribution list. There are three ways to specify the list.

The list may be a simple array of strings:

$queue = MQSeries::Queue->new
  (
   QueueManager 	=> "FOO",
   Queue 		=> [qw( QUEUE1 QUEUE2 QUEUE3 )],
  )

or, it can be an array of arrays, each one specifying the queue and queue manager name of the target queue:

  $queue = MQSeries::Queue->new
    (
     QueueManager 	=> "FOO",
     Queue 		=> [
			    [qw( QUEUE1 QM1 )],
			    [qw( QUEUE2 QM2 )],
			    [qw( QUEUE3 QM3 )],
			   ],
    )

or finally, it can be an array of hash references, each naming the queue and queue manager:

$queue = MQSeries::Queue->new
  (
   QueueManager 	=> "FOO",
   Queue 		=> 
   [
    {
     ObjectName	=> 'QUEUE1',
     ObjectQMgrName	=> 'QM1',
    },
    {
     ObjectName	=> 'QUEUE2',
     ObjectQMgrName	=> 'QM2',
    },
    {
     ObjectName	=> 'QUEUE3',
     ObjectQMgrName	=> 'QM3',
    },
   ],
  )

In the latter two cases, the queue manager names are optional. Which method to use is largely a choice of style.

Mode

If the Mode key is specified, then the Options key may NOT be specified. These are mutually exclusive.

The Mode is a shorthand for opening the Queue for output or input, without requiring the developer to work with the Options flags directly. The mode may have one of the following values, which implies the Options shown.

Mode Value       Equivalent MQOPEN Options
==========       =========================
input            MQOO_INPUT_AS_Q_DEF | MQOO_FAIL_IF_QUIESCING
input_shared     MQOO_INPUT_SHARED | MQOO_FAIL_IF_QUIESCING
input_exclusive  MQOO_INPUT_EXCLUSIVE | MQOO_FAIL_IF_QUIESCING
output           MQOO_OUTPUT | MQOO_FAIL_IF_QUIESCING
Options

If the Options key is specified, then the Mode key may NOT be specified. These are mutually exclusive. This is a used as-is as the Options field in the MQOPEN call. Refer to the MQI documentation on MQOPEN() for more details.

DisableAutoResize

This is a Boolean value, which if true, will disable the automatic resizing of the message buffer when it is either truncated, or the converted message will not fit.

See the Get() method documentation for more information.

NoAutoOpen

This will disable the implicit call to the Open() method by the constructor, thus requiring the application to call it itself. This allows for more fine-grained error checking, since the constructur will then fail only if there is a problem parsing the constructor arguments. The subsequent call to Open() can be error checked independently of the new() constructor.

ObjDesc

The value of this key is a hash refernece which sets the key/values of the MsgDesc structure. See the "MQSeries Application Programming Reference" documentation for the possible keys and values of the MQOD structure.

Also, see the examples section for specific usage of this feature. This is one area of the API which is not easily hidden; you have to know what you are doing.

Carp

This key specifies a code reference to a routine to replace all of the carp() calls in the API, allowing the user of the API to trap and handle all of the error message generated internally, or simply redirect how they get logged.

For example, one might want everything to be logged via syslog:

sub MyLogger {
    my $message = @_;
    foreach my $line ( split(/\n+/,$message) ) {
        syslog("err",$message);
    }
}

Then, one tells the object to use this routine:

my $queue = MQSeries::Queue->new
  (
   QueueManager 	=> 'some.queue.manager',
   Queue 		=> 'SOME.QUEUE',
   Carp 		=> \&MyLogger,
  ) or die("Unable to connect to queue manager.\n");

The default, as one might guess, is Carp::carp();

PutConvert, GetConvert

These are CODE references to subroutines which are used to convert the data in a MQSeries::Message object prior to passing it to the MQPUT MQI call, or convert the data retreived from the queue by the MQGET MQI call before inserting it into a MQSeries::Message object.

See the MQSeries::QueueManager documentation for details on the calling and error handling syntax of these subroutines, as well as an example using Storable.pm to pass perl references around in MQSeries messages.

If this key is not specified, then the MQSeries::Queue objects will inherit these CODE references from the MQSeries::QueueManager object. If the QueueManager key was given as a name, and not an object, then no conversion is performed.

Note that these can be overridden for individual Put() or Get() calls, if necessary for a single message, just as PutConvert can be overridden for a single Put1() call (see MQSeries::QueueManager docs).

Also, note that to disable these for a single message, or a single queue, one would simply pass a function that returns its first argument.

PutConvert => sub { return $_[0]; },
GetConvert => sub { return $_[0]; },

See also the section "CONVERSION PRECEDENCE" in the MQSeries::QueueManager documentation.

CompCode, Reason

WARNING: These keys are deprecated, and their use no longer encouraged. They are left in place only for backwards compabitility.

See the docs for the NoAutoOpen argument, and the Open() method.

When the constructor encounters an error, it returns nothing, and you can not make method calls off of a non-existent object. Thus, you do not have access to the CompCode() and Reason() method calls. If you want to extract these values, you will have to pass a scalar reference value to the constructor, for example:

my $CompCode = MQCC_FAILED;
my $Reason = MQRC_UNEXPECTED_ERROR;

my $queue = MQSeries::Queue->new
  (
   QueueManager		=> 'some.queue.manager',
   Queue			=> 'SOME,QUEUE',
   CompCode			=> \$CompCode,
   Reason			=> \$Reason,
  ) || die "Unable to open queue: CompCode => $CompCode, Reason => $Reason\n";

But, this is ugly (authors opinion, but then, he gets to write the docs, too).

NOTE: If you let the MQSeries::Queue object implicitly create the MQSeries::QueueManager object, and that fails, you will NOT get the CompCode/Reason values which resulted. This is intentional. If you want this level of granularity, then instantiante the MQSeries::QueueManager object yourself, and pass it to the MQSeries::Queue constructor.

See the ERROR HANDLING section as well.

Open

This method will accept the same Options and Mode arguments which can be passed to the constructor (new()), and it merely calls MQOPEN() to open the actual queue object.

This method is called automatically by the constructor, unless the NoAutoOpen argument is given.

Note that this is a new method as of the 1.06 release, and is provided to enable more fine grained error checking. See the ERROR HANDLING section.

Close

The arguments to this method are a hash of key/value pairs, and currently only one key is supported: "Options". The value is the Options argument to MQCLOSE(). This will override the "CloseOptions" passed to the constructor. This method merely calls MQCLOSE() to close the actual queue object.

It is important to note that normally, this method need not be called, since it is implicitly called via the object destructor. If the Close() call errors need to be handled, then it can be done explicitly. See the ERROR HANDLING section.

Put

This method wraps the MQPUT call. The arguments are a hash, with the following key/value pairs (required keys are marked with a '*'):

Key         Value
===         =====
Message*    MQSeries::Message object
PutMsgOpts  HASH Reference
PutMsgRecs  ARRAY Reference
Sync        Boolean
PutConvert  CODE Reference
Message

This argument is the message to be placed onto the queue. The value must be an MQSeries::Message object.

PutMsgOpts

This option allows the programmer complete control over the PutMsgOpts structure passed to the MQPUT() call. If this option is specified, then the Sync option is simply ignored.

The default options specified by the OO API are

MQGMO_FAIL_IF_QUIESCING

See the MQPUT() documentation for the use of PutMsgOpts.

PutMsgRecs

This argument is relevant only when using distribution lists.

The value is an ARRAY reference, specifying the put message records for the individual queues in the distribution list. Normally, these are specified as part of the PutMsgOpts, but this API attempts to hide the complexity of the PutMsgOpts structure from the user.

When using distribution lists, PutMsgRecs are often necessary to control how the MsgId, CorrelId, and three other specific fields in the MsgDesc are handled.

For details, see the MQPUT() and MQPUT1() documentation in MQSeries(3).

Sync

This is a flag to indicate that the Syncpoint option is to be used, and the message(s) not committed to the queue until an MQBACK or MQCOMM call is made. These are both wrapped with the Backout() and Commit() methods respectively.

The value is simply interpreted as true or false.

PutConvert

This is a means of overriding the PutConvert routine specified for the MQSeries::Queue object, for a single Put. See the new() documentation for more details.

Get

This method wraps the MQGET call. The arguments are a hash, with the following key/value pairs (required keys are marked with a '*'):

Key                Value
===                =====
Message*           MQSeries::Message object
GetMsgOpts         HASH Reference
Wait               Numeric Value
Sync               Boolean
DisableAutoResize  Boolean
GetConvert         CODE Reference

The return value of Get() is either 1, 0 or -1. Success or failure can still be interpreted in a Boolean context, with the following caveat. A value of 1 is returned when a message was successfully retreives from the queue. A value of 0 is returned if some form of error was encountered. A value of -1 is returned when no message was retreived, but the MQGET call failed with a Reason Code of "MQRC_NO_MSG_AVAILABLE".

The last condition (-1) may or may not be an error, depending on your application. This merely indicates that a message matching the specified MsgDesc criteria was not found, or perhaps the queue was just empty. You have to decide how to handle this.

By default, the Get() method will also handle the message buffer size being too small for two very specific cases.

Case 1: Reason == MQRC_TRUNCATED_MSG_FAILED

In this case, the BufferLength of the Message object is reset to the DataLength value returned by the MQGET() call, and the MQGET() call is redone.

Case 2: Reason == MQRC_CONVERTED_MSG_TOO_BIG

In this case, the BufferLength of the Message object is reset to twice the DataLength value returned by the MQGET() call, and the MQGET() call is redone. Doubling the size is probably overkill, but there is no deterministic way of finding the actual size required. Since most of the conversions are character set mappings, we are assuming that double will always be sufficient.

Note that this functionality can be disabled, if not desired, by specifying DisableAutoResize as an argument to either the MQSeries::Queue->new() constructor or the Get() method.

Message

This argument is the MQSeries::Message object into which the message extracted from the queue is placed. This can be a 'raw' MQSeries::Message, or it can be one with the MsgId, or some other key in the MsgDesc explicitly specified, in order to retreive a specific message. See MQSeries::Message documentation for more details.

GetMsgOpts

This option allows the programmer complete control over the GetMsgOpts structure passed to the MQGET() call. If this option is specified, then the Sync, and Wait options are simply ignored.

The default options specified by the OO API are

MQGMO_FAIL_IF_QUIESCING
MQGMO_CONVERT

See the MQGET() documentation for the use of GetMsgOpts.

Wait

This is a numeric value, interpreted as follows. If the value is greater than zero, then the MQGMO_WAIT option is used, and the value is set as the WaitInterval in the GetMsgOpts structure.

Remember, this value is interpreted by the API as a number of milliseconds, not seconds (the rest of the OO-API uses seconds).

If the value is 0, then the MQGMO_NO_WAIT option is used.

If the value is -1, then the MQGMO_WAIT option is used, and the WaitInterval is set to MQWI_UNLIMITED, meaning the MQGET call will block until a message appears on the queue.

The default is 0, the same as the MQGET() call itself.

NOTE: MQWI_UNLIMITED should be used with caution, as applications which block forever can prevent queue managers from shutting down elegantly, in some cases.

Sync

This is a flag to indicate that the Syncpoint option is to be used, and the message(s) not committed to the queue until an MQBACK or MQCMIT call is made. These are both wrapped with the Backout() and Commit() methods respectively.

The value is simply interpreted as true or false.

DisableAutoResize

This is a Boolean value, which if true, will disable the automatic resizing of the message buffer when it is either truncated, or the converted message will not fit.

GetConvert

This is a means of overriding the GetConvert routine specified for the MQSeries::Queue object, for a single Get. See the new() documentation for more details.

Inquire

This method is an interface to the MQINQ() API call, however, it takes more convenient, human-readable strings in place of the C macros for the selectors, as well as supports more readable strings for some of the data values as well.

For example, to query the MaxMsgLength and MaxQDepth of a queue:

my %qattr = $queue->Inquire( qw(MaxMsgLength MaxQDepth) );

The argument to this method is a list of "selectors", or Queue attributes, to be queried. The following table shows the complete set of possible keys, and their underlying C macro.

Note that this list is all-inclusive, and that many of these are not supported on some of the MQSeries platforms. Consult the IBM documentation for such details.

Key				Macro
===				=====
AlterationDate              MQCA_ALTERATION_DATE
AlterationTime              MQCA_ALTERATION_TIME
BackoutRequeueName          MQCA_BACKOUT_REQ_Q_NAME
BackoutThreshold            MQIA_BACKOUT_THRESHOLD
BaseQName                   MQCA_BASE_Q_NAME
ClusterDate                 MQCA_CLUSTER_DATE
ClusterName                 MQCA_CLUSTER_NAME
ClusterNamelist             MQCA_CLUSTER_NAMELIST
ClusterQType                MQIA_CLUSTER_Q_TYPE
ClusterTime                 MQCA_CLUSTER_TIME
CreationDate                MQCA_CREATION_DATE
CreationTime                MQCA_CREATION_TIME
CurrentQDepth               MQIA_CURRENT_Q_DEPTH
DefBind                     MQIA_DEF_BIND
DefInputOpenOption          MQIA_DEF_INPUT_OPEN_OPTION
DefPersistence              MQIA_DEF_PERSISTENCE
DefPriority                 MQIA_DEF_PRIORITY
DefinitionType              MQIA_DEFINITION_TYPE
DistLists                   MQIA_DIST_LISTS
HardenGetBackout            MQIA_HARDEN_GET_BACKOUT
HighQDepth                  MQIA_HIGH_Q_DEPTH
InhibitGet                  MQIA_INHIBIT_GET
InhibitPut                  MQIA_INHIBIT_PUT
InitiationQName             MQCA_INITIATION_Q_NAME
MaxMsgLength                MQIA_MAX_MSG_LENGTH
MaxQDepth                   MQIA_MAX_Q_DEPTH
MsgDeliverySequence         MQIA_MSG_DELIVERY_SEQUENCE
MsgDeqCount                 MQIA_MSG_DEQ_COUNT
MsgEnqCount                 MQIA_MSG_ENQ_COUNT
OpenInputCount              MQIA_OPEN_INPUT_COUNT
OpenOutputCount             MQIA_OPEN_OUTPUT_COUNT
ProcessName                 MQCA_PROCESS_NAME
QDepthHighEvent             MQIA_Q_DEPTH_HIGH_EVENT
QDepthHighLimit             MQIA_Q_DEPTH_HIGH_LIMIT
QDepthLowEvent              MQIA_Q_DEPTH_LOW_EVENT
QDepthLowLimit              MQIA_Q_DEPTH_LOW_LIMIT
QDepthMaxEvent              MQIA_Q_DEPTH_MAX_EVENT
QDesc                       MQCA_Q_DESC
QMgrIdentifier              MQCA_Q_MGR_IDENTIFIER
QMgrName                    MQCA_CLUSTER_Q_MGR_NAME
QName                       MQCA_Q_NAME
QNames                      MQCACF_Q_NAMES
QServiceInterval            MQIA_Q_SERVICE_INTERVAL
QServiceIntervalEvent       MQIA_Q_SERVICE_INTERVAL_EVENT
QType                       MQIA_Q_TYPE
RemoteQMgrName              MQCA_REMOTE_Q_MGR_NAME
RemoteQName                 MQCA_REMOTE_Q_NAME
RetentionInterval           MQIA_RETENTION_INTERVAL
Scope                       MQIA_SCOPE
Shareability                MQIA_SHAREABILITY
TimeSinceReset              MQIA_TIME_SINCE_RESET
TriggerControl              MQIA_TRIGGER_CONTROL
TriggerData                 MQCA_TRIGGER_DATA
TriggerDepth                MQIA_TRIGGER_DEPTH
TriggerMsgPriority          MQIA_TRIGGER_MSG_PRIORITY
TriggerType                 MQIA_TRIGGER_TYPE
Usage                       MQIA_USAGE
XmitQName                   MQCA_XMIT_Q_NAME

The return value of this method is a hash, whose keys are those given as arguments, and whose values are the queried queue attributes. In most cases, the values are left unmolested, but in the following cases, the values are mapped to more readable strings.

DefBind (integer)
Key				Macro
===				=====
OnOpen                      MQBND_BIND_ON_OPEN
NotFixed                    MQBND_BIND_NOT_FIXED
DefinitionType (integer)
Key				Macro
===				=====
Permanent                   MQQDT_PERMANENT_DYNAMIC
Temporary                   MQQDT_TEMPORARY_DYNAMIC
DefInputOpenOption (integer)
Key				Macro
===				=====
Exclusive                   MQOO_INPUT_EXCLUSIVE
Shared                      MQOO_INPUT_SHARED
MsgDeliverySequence (integer)
Key				Macro
===				=====
FIFO                        MQMDS_FIFO
Priority                    MQMDS_PRIORITY
QServiceIntervalEvent (integer)
Key				Macro
===				=====
High                        MQQSIE_HIGH
None                        MQQSIE_NONE
OK                          MQQSIE_OK
QType (integer)
Key				Macro
===				=====
Alias                       MQQT_ALIAS
All                         MQQT_ALL
Cluster                     MQQT_CLUSTER
Local                       MQQT_LOCAL
Model                       MQQT_MODEL
Remote                      MQQT_REMOTE
Scope (integer)
Key				Macro
===				=====
Cell                        MQSCO_CELL
QMgr                        MQSCO_Q_MGR
TriggerType (integer)
Key				Macro
===				=====
Depth                       MQTT_DEPTH
Every                       MQTT_EVERY
First                       MQTT_FIRST
None                        MQTT_NONE
Usage (integer)
Key				Macro
===				=====
Normal                      MQUS_NORMAL
XMITQ                       MQUS_TRANSMISSION

Set

This method is an interface to the MQSET() API call, and like Inquire(), it takes more convenient, human-readable strings in place of the C macros.

For example, to put inhibit a queue:

$queue->Set( InhibitPut => 1 );

The argument to this method is a hash of key/value pairs representing queue attributes to be set. The MQSET() API supports setting a very limited subset of specific queue attributes. The following table shows the complete set of possible keys, and their underlying C macros.

Key				Macro
===				=====
InhibitGet                  MQIA_INHIBIT_GET
InhibitPut                  MQIA_INHIBIT_PUT
DistLists                   MQIA_DIST_LISTS
TriggerControl              MQIA_TRIGGER_CONTROL
TriggerData                 MQCA_TRIGGER_DATA
TriggerDepth                MQIA_TRIGGER_DEPTH
TriggerMsgPriority          MQIA_TRIGGER_MSG_PRIORITY
TriggerType                 MQIA_TRIGGER_TYPE

In addition, the data value for the "TriggerType" key can have one of the following values:

Key				Macro
===				=====
Depth                       MQTT_DEPTH
Every                       MQTT_EVERY
First                       MQTT_FIRST
None                        MQTT_NONE

All of the other values are simply Boolean (0 or 1), with the exception of "TriggerData", which is a string.

This method call returns true upon success, and false upon failure. CompCode() and Reason() will be set appropriately.

ObjDesc

This method can be used to query the ObjDesc data structure. If no argument is given, then the ObjDesc hash reference is returned. If a single argument is given, then this is interpreted as a specific key, and the value of that key in the ObjDesc hash is returned.

Backout

This method takes no arguments, and merely calls MQBACK. It returns true on success, and false on failure.

NOTE: This operation is in reality not specific to the Queue, but rather to the Queue Manager connection. Because the API does not require the developer to specifically open a Queue Manager connection (via an MQSeries::QueueManager object), but will do so implicitly (see the new() documentation above), these methods are provided as part of the MQSeries::Queue API. Note, however, that this does NOT imply that syncpoint operations can be performed at the individual Queue level. Transactions are still per-queue manager connection.

Commit

This method takes no arguments, and merely calls MQCMIT. It returns true on success, and false on failure.

NOTE: The same comments for Backout() apply here. This is really a Queue Manager connection operation.

ERROR HANDLING

Most methods return a true or false value indicating success of failure, and internally, they will call the Carp subroutine (either Carp::carp(), or something user-defined) with a text message indicating the cause of the failure.

In addition, the most recent MQI Completion and Reason codes will be available via the CompCode() and Reason() methods:

$queue->CompCode()
$queue->Reason()

When distribution lists are used, then it is possible for a list of reason codes to be returned by the API. Normally, these are buried inside the ObjDesc strucure, but they are also available via the

$queue->Reasons()

method. In this case, the $queue->Reason() will always return MQRC_MULTIPLE_REASONS. The return value of the Reasons() method is an array reference, and each array item is a hash reference with two keys: CompCode and Reason. These correspond, respectively, with the CompCode and Reason associated with the individual queues in the distribution list.

For example, the Reason code associated with the 3rd queue in the list would be:

$queue->Reasons()->[2]->{Reason}

In the case of the constructor new(), which returns nothing when it fails, these methods are not available. Most applications will not need to handle the specific CompCode and Reason when the instantiation fails, but if necessary, these can be obtained in one of two ways.

The older method, which is supported for backwards compabitility but strongly discouarged, is to pass references to scalar variables to new(). See the new() documentation above for more details.

The newer method would be to explicitly call the Open() method, and error check it yourself. This will mean that the constructor will now fail only if there is an error processing the constructor arguments, as opposed to an error in the MQSeries infrastructure.

Some examples should make this clear.

The simplest way to create an MQSeries::Queue object is:

my $queue = MQSeries::Queue->new
  (
   QueueManager		=> 'some.queue.manager',
   Queue			=> 'SOME.QUEUE',
   Mode			=> 'input',
  ) || die;

But in this case, either the connection to the queue manager or the open of the queue could fail, and your application will not be able to determine why.

In order to explicitly have access to the CompCode and Reason one would do the following:

# Explicitly create your own MQSeries::QueueManager object
my $qmgr = MQSeries::QueueManager->new
  (
   QueueManager		=> 'some.queue.manager',
   DisableAutoConnect		=> 1,
  ) || die "Unable to instantiate MQSeries::QueueManager object\n";

# Call the Connect method explicitly
unless ( $qmgr->Connect() ) {
  die("Connection to queue manager failed\n" .
      "CompCode => " . $qmgr->CompCode() . "\n" .
      "Reason   => " . $qmgr->Reason() . "\n");
}

my $queue = MQSeries::Queue->new
  (
   QueueManager		=> $qmgr,
   Queue			=> 'SOME.QUEUE',
   Mode			=> 'input',
   NoAutoOpen			=> 1,
  ) || die "Unable to instantiate MQSeries::Queue object\n";

# Call the Open method explicitly
unless ( $queue->Open() ) {
  die("Open of queue failed\n" .
      "CompCode => " . $queue->CompCode() . "\n" .
      "Reason   => " . $queue->Reason() . "\n");
}

SEE ALSO

MQSeries(3), MQSeries::QueueManager(3), MQSeries::Message(3), MQSeries::Message::Storable(3)