status = false; switch ($_which) { case BROKER_QUEUE_AI : $resource = RESOURCE_ADMIN; $queue = BROKER_QUEUE_AI; $labelClient = 'gacAdminInClient<'; break; case BROKER_QUEUE_S : $resource = RESOURCE_TERCERO; $queue = BROKER_QUEUE_S; $labelClient = 'gacSessionClient<'; break; default : consoleLog('cACI: ', CON_ERROR, ERROR_CONFIG_RESOURCE_404 . $_which); return; break; } $this->queueName = gasConfig::$settings[CONFIG_BROKER_SERVICES][CONFIG_BROKER_QUEUE_TAG] . $queue; try { $this->rabbitConnection = gasResourceManager::fetchResource($resource); if (is_null($this->rabbitConnection)) return; $this->rabbitChannel = $this->rabbitConnection->channel(); $label = uniqid($labelClient . $_fw . '>:'); list($this->rabbitCallbackQueue, ,) = $this->rabbitChannel->queue_declare($label . uniqid(), false, false, false, true); $this->rabbitChannel->basic_consume($this->rabbitCallbackQueue, '', false, true, false, false); $this->rabbitResponse = null; $this->status = true; } catch (AMQPRuntimeException | AMQPTimeoutException | Throwable | TypeError $t) { $hdr = basename(__METHOD__) . AT . __LINE__ . COLON; @handleExceptionMessaging($hdr, $t->getMessage(), $foo, true); } } /** * call() -- public method * * This method is invoked outside of the class and is the entry point for publishing a message request to the * AdminIn broker. It creates a new AMQP message and publishes it to the queue (defined in the constructor), * and then exits, returning a true message indicating that the messages was successfully published. * * Since the AdminIN broker is a fire-n-forget broker, there are no return messages to block-and-wait on. * * If an exception is raised by this class, then a false value will be returned. * * NOTE: the true/false return values are not, in any way, a reflection of the processing success/failure on the * remote service. The general RoT is that if we can publish the request, then we can only assume that the request * was successfully consumed and processed. * * @author mike@givingassistant.org * @version 1.0 * * @param $_data * @return bool * * HISTORY: * ======== * 06-15-17 mks original coding * 08-17-17 mks CORE-500: returning a boolean that actually indicates if we successfully published the event * 09-19-19 mks DB-136: refactored exception handling, fixed the AMQPMessage create call * 10-20-20 mks DB-168: better exception handling, removed channel close b/c autodelete is on * */ public function call($_data): bool { $this->rabbitResponse = null; $this->rabbitCorrelationID = uniqid(); $success = false; try { $rabbitMessage = new AMQPMessage((string)$_data); $this->rabbitChannel->basic_publish($rabbitMessage, '', $this->queueName); $success = true; } catch (AMQPTimeoutException | AMQPRuntimeException | Throwable $e) { $hdr = basename(__METHOD__) . AT . __LINE__ . COLON; @handleExceptionMessaging($hdr, $e->getMessage(), $foo, true); } return ($success); } public function __destruct() { // As of PHP 5.3.10 destructors are not run on shutdown caused by fatal errors. // // destructor is registered shut-down function in constructor -- so any recovery // efforts should go in this method. try { if (!is_null($this->rabbitChannel)) { $this->rabbitChannel->close(); $this->rabbitConnection->close(); } } catch (AMQPRuntimeException | AMQPTimeoutException | Throwable | TypeError $t) { $hdr = basename(__METHOD__) . AT . __LINE__ . COLON; @handleExceptionMessaging($hdr, $t->getMessage(), $foo, true); } } }