示例#1
0
 /**
  * Retrieves the error messages from a MQ error queue.
  *
  * @throws Exception
  */
 public function readErrorMessages()
 {
     $msgArr = array();
     try {
         // connect to queue manager
         $this->getSSLConnection();
         // $mqods = array('ObjectName' => $queue_name, 'ObjectQMgrName' => $queue_manager);
         $mqods = array('ObjectName' => $this->errorQueue);
         // open the connection to the given queue
         mqseries_open($this->connection, $mqods, MQSERIES_MQOO_INPUT_AS_Q_DEF | MQSERIES_MQOO_FAIL_IF_QUIESCING | MQSERIES_MQOO_OUTPUT, $this->obj, $comp_code, $reason);
         // $obj now holds the reference to the queue object
         while ($comp_code != MQSERIES_MQCC_FAILED) {
             $msg = null;
             // setup empty message descriptor.
             $mdg = array();
             // setup get message options
             $gmo = array('Options' => MQSERIES_MQGMO_FAIL_IF_QUIESCING | MQSERIES_MQGMO_WAIT, 'WaitInterval' => 30000);
             // get the message from the queue
             mqseries_get($this->connection, $this->obj, $mdg, $gmo, 4194304, $msg, $data_length, $comp_code, $reason);
             if ($reason != MQSERIES_MQRC_NONE) {
                 if ($reason == MQSERIES_MQRC_NO_MSG_AVAILABLE) {
                     $this->log->info("No More Messages");
                 } else {
                     printf("GET CompCode:%d Reason:%d Text:%s<br>", $comp_code, $reason, mqseries_strerror($reason));
                     $this->log->info("\n\nCould not read the error message from the error queue.");
                 }
             } else {
                 if (empty($msg)) {
                     continue;
                 }
                 $msgKey = date('Y-m-d', strtotime($mdg['PutDate'])) . ' ' . $mdg['PutTime'];
                 $msgArr[$msgKey] = $msg;
                 $this->log->info("\nMessage read successfully from the error queue.\n");
                 $this->log->info("\nFirst 2000 characters of the read message: \n" . substr($msg, 0, 1999) . " ...");
             }
         }
         // close the object reference $obj
         $this->closeTarget();
         // disconnect from the queue manager
         $this->disconnect();
     } catch (Exception $e) {
         $message = "\nAn error occurred while reading the messages in the error queue. " . $e->getMessage() . "\n";
         $this->log->error($message);
         throw new Exception($message);
     }
     return $msgArr;
 }
示例#2
0
 /**
  * Opens a queue on a queue manager
  * 
  * @param Open\Params $params
  * @return boolean
  * @throws QueueManagerConnectionFailedException If we cannot connect to queue manager
  */
 public function openQueueOnQM($params)
 {
     if (!$this->isConnected) {
         $connected = $this->connect();
         if (!$connected) {
             throw new QueueManagerConnectionFailedException("Could not connect to queue manager");
         }
     }
     $this->completionCode = null;
     $this->reason = null;
     $this->logger->debug(__METHOD__ . "(): ABOUT TO CALL mqseries_open().");
     mqseries_open($this->connection, $params->buildMQODS(), $params->option, $this->queue, $this->completionCode, $this->reason);
     $this->logger->debug(__METHOD__ . "(): mqseries_open() has been called.");
     if ($this->completionCode !== MQSERIES_MQCC_OK) {
         $this->logger->error(__METHOD__ . "(): " . sprintf("Open CompCode:%d Reason:%d\n", $this->completionCode, $this->reason));
         $this->isQueueOpened = false;
     } else {
         $this->logger->info(__METHOD__ . "(): Queue " . $params->objectName . " successfully opened.");
         $this->isQueueOpened = true;
     }
     return $this->isQueueOpened;
 }