/** * 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; }
/** * Get a message from an open queue * * @param Get\Params $params * @return string|boolean * @throws QueueUnavailableException when there is no open queue */ public function getMessageFromQueue($params) { if (!$this->isConnected || !$this->isQueueOpened) { throw new QueueUnavailableException("There is no queue to get a message from!"); } $mqmd = $params->buildMQMD(); $mqgmo = $params->buildMQGMO(); mqseries_get($this->connection, $this->queue, $mqmd, $mqgmo, $this->defaultMessageBuffer, $this->msg, $this->msgSize, $this->completionCode, $this->reason); if ($this->completionCode !== MQSERIES_MQCC_OK) { $this->logger->error(__METHOD__ . "(): ERROR " . sprintf("GET CompCode:%d Reason:%d Text:%s\n", $this->completionCode, $this->reason, mqseries_strerror($this->reason))); //Check if response is "2080 MQRC TRUNCATED MSG FAILED" and if so, increase message buffer: if ($this->getLastCompletionReasonCode() == 2080 && $this->getLastCompletionCode() == MQSERIES_MQCC_WARNING) { $this->logger->notice('Message buffer too small. Increasing to ' . $this->getLastMessageSize() . ' and trying again...'); $this->setDefaultMessageBuffer($this->getLastMessageSize()); return $this->getMessageFromQueue($params); } elseif ($this->getLastCompletionReasonCode() == 2033 && $this->getLastCompletionCode() == MQSERIES_MQCC_FAILED) { //The queue is empty throw new QueueIsEmptyException($this->getLastCompletionReason(), $this->getLastCompletionReasonCode()); } else { return false; } } else { return $this->msg; } }